Aug-25-2020, 04:37 PM
you could write your timer as a method, and have it call your change image upon completion like example below
example replace None with your method:
example replace None with your method:
import tkinter as tk from datetime import datetime class TkSimpleTimer: def __init__(self, parent): self.parent = parent def timeit(self, t_time): start_time = datetime.now().strftime("%H:%M:%S:%f") print(f"\nTimer started at: {start_time}, will delay {t_time} ms") self.parent.after(t_time, None) end_time = datetime.now().strftime("%H:%M:%S:%f") print(f"Timer finished at: {end_time}") if __name__ == '__main__': root = tk.Tk() tst = TkSimpleTimer(root) for i in range(5): # time is in miliseconds tst.timeit(i*1000) root.destroy() root.mainloop()
Output:Timer started at: 12:37:38:872230, will delay 0 ms
Timer finished at: 12:37:38:872285
Timer started at: 12:37:38:872302, will delay 1000 ms
Timer finished at: 12:37:39:873420
Timer started at: 12:37:39:873499, will delay 2000 ms
Timer finished at: 12:37:41:874964
Timer started at: 12:37:41:875117, will delay 3000 ms
Timer finished at: 12:37:44:875973
Timer started at: 12:37:44:876150, will delay 4000 ms
Timer finished at: 12:37:48:876959