My aim is to create a simple timer program. It updates itself constantly until the stopButton is pressed. However, I am unsure how to stop the tick function from running so that the timer stays the same once the stopButton is pressed.
This is my code so far:
import tkinter
root = tkinter.Tk()
root.title('Timer')
root.state('zoomed')
sec = 0
def tick():
global sec
sec += 0.1
sec = round(sec,1)
timeLabel.configure(text=sec)
root.after(100, tick)
def stop():
# stop the timer from updating.
timeLabel = tkinter.Label(root, fg='green',font=('Helvetica',150))
timeLabel.pack()
startButton = tkinter.Button(root, text='Start', command=tick)
startButton.pack()
stopButton = tkinter.Button(root, text='Stop', command=stop)
stopButton.pack()
root.mainloop()
What would be a possible way of stopping the tick()
function?
Any help would be greatly appreciated!