Kann mir jemand erklären, wo der fehler ist(Python Timer Tk)?
Ich habe versucht einen timer zu machen, jedoch funktioniert dieser nicht recht.
from tkinter import *
from tkinter.ttk import *
from time import sleep
root_timer = Tk()
timer = 10
lbl_timer = Label(root_timer, font=("Times New Roman", 26, "bold"),
background="white",
foreground="black")
lbl_timer.config(text=str(timer))
lbl_timer.pack(anchor="center")
def timer_up_press():
global timer
timer += 1
lbl_timer.config(text=str(timer))
lbl_timer.pack(anchor="center")
def timer_down_press():
global timer
if timer == 0:
print()
else:
timer -= 1
lbl_timer.config(text=str(timer))
lbl_timer.pack(anchor="center")
def timer_start_press():
global timer
while True:
if timer == 0:
lbl_timer.config(text='Time is Up')
sleep(1)
else:
timer -= 1
lbl_timer.config(text=str(timer))
sleep(1)
button_timer_up = Button(root_timer, text='Up', command=timer_up_press)
button_timer_down = Button(root_timer, text='Down', command=timer_down_press)
button_timer_start = Button(root_timer, text='Start', command=timer_start_press)
button_timer_up.pack()
button_timer_down.pack()
button_timer_start.pack()
root_timer.mainloop()