Python Forum
[Tkinter] tkinter: after issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] tkinter: after issue
#2
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:
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
Reply


Messages In This Thread
tkinter: after issue - by edwin6938 - Aug-25-2020, 02:37 PM
RE: tkinter: after issue - by Larz60+ - Aug-25-2020, 04:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,114 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  Super basic tkinter arduino issue Kurta 3 2,414 Jan-07-2021, 05:22 PM
Last Post: deanhystad
Photo tkinter issue mate 4 2,536 Dec-06-2020, 09:03 PM
Last Post: mate
  Issue in Tkinter with winfo_class() and LabelFrame ReDefendeur 1 2,741 Oct-05-2020, 05:52 AM
Last Post: Jeff900
  Tkinter: increasing numbers and Radiobutton issue PeroPuri 1 2,167 Apr-13-2020, 05:48 PM
Last Post: deanhystad
  [Tkinter] tkinter issue with variables carrying over between functions PengEng 1 1,743 Apr-06-2020, 06:13 PM
Last Post: deanhystad
  Issue on tkinter with buttons Reldaing 1 2,448 Jan-07-2020, 08:21 AM
Last Post: berckut72
  [Tkinter] Tkinter window issue frequency 4 3,353 Dec-24-2018, 10:49 AM
Last Post: frequency
  Tkinter positional information issue thatguy14 4 3,417 Jul-05-2018, 06:49 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020