Python - Minutnik w kanwie tkinter
Witam Chciałbym utworzyć minutnik w podprogramie, który jest następnie wyświetlany na płótnie. Nie jestem do końca pewny, od czego zacząć. Zrobiłem kilka badań na ten temat i byłem w stanie stworzyć jedną z funkcji time.sleep (x), ale ta metoda zamroziła cały program, który nie jest tym, za czym się podążam . Sprawdziłem też inne pytania dotyczące timera i spróbowałem włączyć je do mojego programu, ale nie byłem jeszcze w stanie osiągnąć żadnego sukcesu.
TLDR; Chcę utworzyć minutnik, który odlicza od 60 sekund i jest wyświetlany na płótnie, a następnie musi zrobić coś, gdy zegar osiągnie 0.
Czy ktoś jest w stanie wskazać mi właściwy kierunek?
Z góry dziękuję.
EDYCJA: Z sugestiami pod warunkiem, że próbowałem umieścić je w programie bez większego szczęścia.
Nie jestem pewien, czy w tym kodzie występuje poważny błąd lub czy to zwykły błąd. Błąd, który pojawia się po uruchomieniu, jest poniżej kodu.
To jest część kodu, w której chcę ustawić timer:
def main(): #First thing that loads when the program is executed.
global window
global tkinter
global canvas
global cdtimer
window = Tk()
cdtimer = 60
window.title("JailBreak Bob")
canvas = Canvas(width = 960, height = 540, bg = "white")
photo = PhotoImage(file="main.gif")
canvas.bind("<Button-1>", buttonclick_mainscreen)
canvas.pack(expand = YES, fill = BOTH)
canvas.create_image(1, 1, image = photo, anchor = NW)
window.mainloop()
def buttonclick_mainscreen(event):
pressed = ""
if event.x >18 and event.x <365 and event.y > 359 and event.y < 417 : pressed = 1
if event.x >18 and event.x <365 and event.y > 421 and event.y < 473 : pressed = 2
if event.x >18 and event.x <365 and event.y > 477 and event.y < 517 : pressed = 3
if pressed == 1 :
gamescreen()
if pressed == 2 :
helpscreen()
if pressed == 3 :
window.destroy()
def gamescreen():
photo = PhotoImage(file="gamescreen.gif")
canvas.bind("<Button-1>", buttonclick_gamescreen)
canvas.pack(expand = YES, fill = BOTH)
canvas.create_image(1, 1, image = photo, anchor = NW)
game1 = PhotoImage(file="1.gif")
canvas.create_image(30, 65, image = game1, anchor = NW)
e1 = Entry(canvas, width = 11)
e2 = Entry(canvas, width = 11)
canvas.create_window(390, 501, window=e1, anchor = NW)
canvas.create_window(551, 501, window=e2, anchor = NW)
canvas.after(1, gamescreen)
window.mainloop()
def cdtimer():
canvas.delete(ALL)
global cdtimer
cdtimer -= 1
canvas.create_text(510, 6, text=cdtimer, font="Ubuntu 29 bold", anchor = NW)
if cdtimer == 0:
scorescreen()
else:
canvas.after(1000, gamescreen)
main()
Błąd MSG:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.2/tkinter/__init__.py", line 1402, in __call__
return self.func(*args)
File "/usr/lib/python3.2/tkinter/__init__.py", line 490, in callit
func(*args)
File "/home/ppppwn3d/workspace/Python/JailBreakBob/JailBreakBob.py", line 50, in gamescreen
e1 = Entry(canvas, width = 11)
File "/usr/lib/python3.2/tkinter/__init__.py", line 2372, in __init__
Widget.__init__(self, master, 'entry', cnf, kw)
File "/usr/lib/python3.2/tkinter/__init__.py", line 1952, in __init__
cnf = _cnfmerge((cnf, kw))
File "/usr/lib/python3.2/tkinter/__init__.py", line 71, in _cnfmerge
if isinstance(cnfs, dict):
RuntimeError: maximum recursion depth exceeded while calling a Python object