Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python Tkinter timer animation

#!/usr/bin/env python3

# Display UTC.
# started with https://docs.python.org/3.4/library/tkinter.html#module-tkinter

import tkinter as tk
import time

def current_iso8601():
    """Get current date and time in ISO8601"""
    # https://en.wikipedia.org/wiki/ISO_8601
    # https://xkcd.com/1179/
    return time.strftime("%Y%m%dT%H%M%SZ", time.gmtime())

class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

    def createWidgets(self):
        self.now = tk.StringVar()
        self.time = tk.Label(self, font=('Helvetica', 24))
        self.time.pack(side="top")
        self.time["textvariable"] = self.now

        self.QUIT = tk.Button(self, text="QUIT", fg="red",
                                            command=root.destroy)
        self.QUIT.pack(side="bottom")

        # initial time display
        self.onUpdate()

    def onUpdate(self):
        # update displayed time
        self.now.set(current_iso8601())
        # schedule timer to call myself after 1 second
        self.after(1000, self.onUpdate)

root = tk.Tk()
app = Application(master=root)
root.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: how to read unicode in python 
Python :: convert string to class name python 
Python :: apostrophe in python 
Python :: pytorch freeze layers 
Python :: get first x characters of string python 
Python :: pasal 
Python :: linear congruential generator in python 
Python :: django update model 
Python :: Concatenate strings from several rows using Pandas groupby 
Python :: play mp3 file python 
Python :: delete the content from the entry form in tkinter python 
Python :: check python version kali linux 
Python :: get table selenium python pandas 
Python :: python tkinter define window size 
Python :: how to load keras model from json 
Python :: jupyter upload folder 
Python :: should i make tkinter in classes ? , Best way to structure a tkinter application? 
Python :: python ascii code to string 
Python :: how to change the background of heading in tkinter 
Python :: add to middle of list python 
Python :: turn off xticks matplotlib 
Python :: what is the use of class in python 
Python :: pandas number of columns 
Python :: dataframe pandas to spark 
Python :: concatenate directories python 
Python :: qradiobutton example 
Python :: playsound python 
Python :: how to print two lists side by side in python 
Python :: import word_tokenize 
Python :: pywhatkit docs 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =