So I am making a program that has a timer and the timer works, now I am working with a pause function. After some research, I found a function called after_cancel. This function supposedly should cancel the after function as the after function in this situation creates an infinite loop. How do I use the after_cancel properly in this situation or are there any other possible solutions?
Thanks in advance.
t = 60000
global timerState
timerState = True
def pause():
timerLabel.after_cancel(countdown)
timerState = False
timerButton.config(text="Play", command=countdown)
def countdown():
global t
if t == 0:
timer = "00:00"
timerLabel.config(text=timer)
return
if timerState == False:
timerLabel.after_cancel(countdown)
timerButton.config(text="Play", command=countdown)
return
mins = t / 60000
secs = t / 1000
secs = secs - int(mins) * 60
mills = t
mills = mills - int(secs) * 1000
if timerState == True:
timer = "{:02d}:{:02d}".format(int(mins),int(secs))
timerLabel.config(text=timer)
t -= 1
timerLabel.after(1, countdown)
timerButton.config(text="Pause", command=pause)