Real Time Clock Display In Tkinter
I want to create real time clock using Tkinter and time library. I have created a class but somehow I am not able to figure out my problem. My code from tkinter import * import ti
Solution 1:
Second parameter of after()
should be a function
-when you are giving any- but you are giving a str
object. Hence you are getting an error.
from tkinter import *
import time
root = Tk()
classClock:
def__init__(self):
self.time1 = ''
self.time2 = time.strftime('%H:%M:%S')
self.mFrame = Frame()
self.mFrame.pack(side=TOP,expand=YES,fill=X)
self.watch = Label(self.mFrame, text=self.time2, font=('times',12,'bold'))
self.watch.pack()
self.changeLabel() #first call it manuallydefchangeLabel(self):
self.time2 = time.strftime('%H:%M:%S')
self.watch.configure(text=self.time2)
self.mFrame.after(200, self.changeLabel) #it'll call itself continuously
obj1 = Clock()
root.mainloop()
Also note that:
The callback is only called once for each call to this method. To keep calling the callback, you need to reregister the callback inside itself.
Post a Comment for "Real Time Clock Display In Tkinter"