I am a beginner in Python and I am trying to create a timer in tkinter. I want to have a button which can stop the timer, however I just can't seem to figure out how to do this. I have tried researching about threads and classes but for such a simple task as a timer do I need these complicated concepts?
import tkinter as tk
from tkinter import *
def countdown(count):
# change text in label
label['text'] = count
if count > 0:
# call countdown again after 1000ms (1s)
root.after(1000, countdown, count-1)
def stop():
# THIS IS THE FUNCTION I WANT TO USE TO STOP THE TIMER, HOWEVER I DO NOT KNOW HOW, RIGHT NOT I HAVE JUST PUT exit() WHICH QUITS THE WHOLE PROGRAM
countdown(exit())
root = tk.Tk()
root.geometry('600x600-200-0')
label = tk.Label(root)
label.place(x=35, y=15)
# call countdown first time
countdown(10)
# root.after(0, countdown, 5)
# Button, pressing it leads to greeting command
button = Button(text="OK", command=stop)
button.pack()
root.mainloop()
I was just wondering if there was a simple solution to this problem, as when I was researching all the tkinter stop timers had such complex code. Thank you in advance!