you are looking for the "after()" method in tkinter. I just built you a small example (please find it below). It is a ticking clock.
You can see there, that I use the "after()" method to call the function which accommodates it.
import tkinter as tk
from time import strftime
class MyClock(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# store everything in a frame
self.container = tk.Frame(self)
self.container.pack(side="top", fill="both", expand=True)
# build a clock
self.clock = tk.Label(self, font=('calibri', 40, 'bold'), background='black', foreground='white')
self.clock.grid(column=0, row=0, sticky='nsew', in_=self.container)
self.clock.configure(text=strftime('%H:%M:%S'), height=2)
# Start clock
self.tick()
def tick(self):
self.after(1000, self.tick) # <----------- this is the method you are looking for
# update time shown on your clock label
now_time = strftime('%H:%M:%S')
self.clock.configure(text=now_time)
if __name__ == "__main__":
app = MyClock()
app.mainloop()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…