I found a script on the Internet that creates a timer, but if after launching I close the application with a timer, the script throws an error and turns off. how to make it so that it does not stop, and then continues to work even if the timer window itself is closed
import tkinter as tk
import time
import win32gui
def countdown(timer):
while timer > 0:
timer_label.config(text=f"Time: {timer} sec")
timer -= 1
root.update()
time.sleep(1)
root.attributes("-topmost", True)
root.lift()
win32gui.SetForegroundWindow(root.winfo_id())
root = tk.Tk()
root.title("Timer")
timer_label = tk.Label(root, text="", font=("Helvetica", 16))
timer_label.pack()
timer_duration = 100
countdown(timer_duration)
root.mainloop()
I tried to make an asynchronous function that constantly runs the code with a timer, but nothing worked