Skip to content Skip to sidebar Skip to footer

Python - Countdown Timer Within A Tkinter Canvas

Hello I would like to create a countdown timer within a subroutine which is then displayed on the canvas. I'm not entirely sure of where to begin I've done some research on to it a

Solution 1:

You want to use the after method. The logic goes something like this:

defupdate_clock(self):
    self.counter -= 1if self.counter == 0 :
        do_something()
    else:
        self.after(1000, self.update_clock)

The above will subtract one from the counter. If the counter is zero it does something special. Otherwise, it schedules itself to run again in one second.

Solution 2:

You might want to try threading?

import thread
import time

def myFunct():
    sec =60
    n = 1for i in range(sec/n):
        updateClock()
        time.sleep(n)
    finalFunct()

thread.start_new_thread(myFunct, ())

Just change sec to the initial amount (in seconds), and n to the interval at which you want it to update (in seconds).

Post a Comment for "Python - Countdown Timer Within A Tkinter Canvas"