'Can't make the timer decrease more then once
I am trying to create a timer, which right now looks like this:
#Timer 60 sec.
import time
sec = 60
def updateTimer():
trecker.config(text = sec-1)
trecker.after(1000, updateTimer)
trecker = Label(gui, text = sec)
trecker.place(x=500, y=200)
trecker.after(1000, updateTimer)
And the reason I write here is that it displays 60, changes to 59 and then stops. I tried to loop it with for in range, but it doesn't help. My idea right now, is that it calls for updateTimer
function in the inside of its execution restarting itself. But it, for some reason does nothing.
Solution 1:[1]
sec-1 is just always 59 because 60-1=59. Instead write:
def updateTimer():
sec -= 1
trecker.config(text = sec)
trecker.after(1000, updateTimer)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cresht |
