Stworzenie minutnika z Pythonem i Tkinterem?
Chcę ustawić etykietę w Tkinter używając mojej funkcji odliczania czasu. Teraz wszystko, co robi, to ustawić etykietę na „10” po osiągnięciu 10 i tak naprawdę nie rozumiem dlaczego. Ponadto, nawet jeśli mam wydruk timera na terminalu, zamiast „Time's up!” bit nigdy nie drukuje.
import time
import tkinter as tk
class App():
def __init__(self):
self.root = tk.Tk()
self.label = tk.Label(text="null")
self.label.pack()
self.countdown()
self.root.mainloop()
# Define a timer.
def countdown(self):
p = 10.00
t = time.time()
n = 0
# Loop while the number of seconds is less than the integer defined in "p"
while n - t < p:
n = time.time()
if n == t + p:
self.label.configure(text="Time's up!")
else:
self.label.configure(text=round(n - t))
app=App()