Python 3 Tkinter Script to Build Infinite Digital Clock by Changing Label Value Using Update() Method GUI Desktop App

You are currently viewing Python 3 Tkinter Script to Build Infinite Digital Clock by Changing Label Value Using Update() Method GUI Desktop App

Python 3 Tkinter Script to Build Infinite Digital Clock By Changing Label Value Using Update() Method GUI Desktop App

import tkinter as tk
import time
 
 
class SampleApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.clock = tk.Label(self, text="")
        self.clock.pack()
 
        # start the clock "ticking"
        self.update_clock()
 
    def update_clock(self):
        now = time.strftime("%H:%M:%S", time.gmtime())
        self.clock.configure(text=now)
        # call this function again in one second
        self.after(1000, self.update_clock)
 
 
if __name__ == "__main__":
    app = SampleApp()
    app.mainloop()

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply