Sometimes, we want to schedule updates in Python tkinter.
In this article, we’ll look at how to schedule updates in Python tkinter.
How to schedule updates in Python tkinter?
To schedule updates in Python tkinter, we can use the root.after method.
For instance, we write
import tkinter as tk
import time
class App():
def __init__(self):
self.root = tk.Tk()
self.label = tk.Label(text="")
self.label.pack()
self.update_clock()
self.root.mainloop()
def update_clock(self):
now = time.strftime("%H:%M:%S")
self.label.configure(text=now)
self.root.after(1000, self.update_clock)
app=App()
to add the update_clock method that calls root.after with the timeout in miiliseconds and the update_clock to update the clock after 1 second.
Conclusion
To schedule updates in Python tkinter, we can use the root.after method.