So I have been wanting to make a timer using tkinter that will go on for a particular period of time. The code seems to be working fine and I am getting the output too, but for some reason, if I am resizing or moving the window, the timer pauses by itself and resumes automatically when the resizing is done. If the window is destroyed before the timer ends, I am getting error that reads
Traceback (most recent call last):
File "countdownclock.py", line 23, in <module>
timer()
File "countdownclock.py", line 16, in timer
label.config(text = '{:02d}:{:02d}'.format(mins,secs))
File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1646, in configure
return self._configure('configure', cnf, kw)
File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1636, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!label"
Below is the code I am using. The program is meant to run for 2 minutes
from tkinter import *
from tkinter.ttk import *
import time
root = Tk()
root.title("Clocky")
label = Label(root, font=("screaming-neon",45),background = "black", foreground = "cyan")
label.pack(anchor="center")
def timer():
mins = 0
secs = 0
while mins<2:
#clocktime = '{:02d}:{:02d}'.format(mins,secs)
label.config(text = '{:02d}:{:02d}'.format(mins,secs))
time.sleep(1)
secs = secs+1
if secs==60:
secs=0
mins=mins+1
root.update()
timer()
mainloop()
Thank you for your help