Reputation: 5209
Situation
I have the following Tkinter window:
And in the blank space on the right:
I want to be able to continuously update the time, like on a digital clock.
I will take the present time using:
time.strftime('%H:%<:%S')
I think this involves MultiThreading. But please tell me if there is some other way to do this.
The two white areas are input areas for the user.
Please note that the text will be entered in these fields. I don't want that to be affected.
What I think is that the function that will make the time to change after each second, will run on a different thread than the one that includes the text boxes.
The value of time will be in a Label:
a = Label(root,text=time.strftime('%H:%M:%S'))
a.grid(row=3,column=1)
Please give me the code for this function and also for the multithreading.
Please help me with this issue.
Upvotes: 0
Views: 318
Reputation: 369424
You don't need multithreading.
...
a = Label(root, text=time.strftime('%H:%M:%S'))
def update_time():
a['text'] = time.strftime('%H:%M:%S')
root.after(1000, update_time)
root.after(1000, update_time)
a.grid(row=3, column=1)
...
Upvotes: 2