I've self-taught myself Python and have recently started learning tkinter. I made a simple stopwatch program and I wanted to know if the code is clean and written in a way that the code works efficiently. I would highly appreciate any suggestions on how to improve my code! Thank you!
from tkinter import * import time root = Tk() numberOfSeconds = 0 def counting(): global numberOfSeconds global stopCounting if stopCounting == False: numberOfSeconds += 1 seconds.config(text=str(numberOfSeconds)) seconds.after(1000, counting) elif stopCounting == True: stopCounting = False numberOfSeconds = 0 seconds.config(text=str(numberOfSeconds)) def start(): global stopCounting stopCounting = False stopButton.config(state=NORMAL) seconds.after(1000, counting) def stop(): global stopCounting stopButton.config(state=DISABLED) stopCounting = True seconds = Label(text=str(numberOfSeconds)) startButton = Button(text="Start", command=start) stopButton = Button(text="Stop", command=stop, state=DISABLED) seconds.grid(row=0, column=0, columnspan=2) startButton.grid(row=1, column=0) stopButton.grid(row=1, column=1) root.mainloop()