python tkinter timer animation

Solutions on MaxInterview for python tkinter timer animation by the best coders in the world

showing results for - "python tkinter timer animation"
Davide
09 Jan 2018
1#!/usr/bin/env python3
2
3# Display UTC.
4# started with https://docs.python.org/3.4/library/tkinter.html#module-tkinter
5
6import tkinter as tk
7import time
8
9def current_iso8601():
10    """Get current date and time in ISO8601"""
11    # https://en.wikipedia.org/wiki/ISO_8601
12    # https://xkcd.com/1179/
13    return time.strftime("%Y%m%dT%H%M%SZ", time.gmtime())
14
15class Application(tk.Frame):
16    def __init__(self, master=None):
17        tk.Frame.__init__(self, master)
18        self.pack()
19        self.createWidgets()
20
21    def createWidgets(self):
22        self.now = tk.StringVar()
23        self.time = tk.Label(self, font=('Helvetica', 24))
24        self.time.pack(side="top")
25        self.time["textvariable"] = self.now
26
27        self.QUIT = tk.Button(self, text="QUIT", fg="red",
28                                            command=root.destroy)
29        self.QUIT.pack(side="bottom")
30
31        # initial time display
32        self.onUpdate()
33
34    def onUpdate(self):
35        # update displayed time
36        self.now.set(current_iso8601())
37        # schedule timer to call myself after 1 second
38        self.after(1000, self.onUpdate)
39
40root = tk.Tk()
41app = Application(master=root)
42root.mainloop()
43