我知道 .after 方法,但它需要一個函式才能使用。我嘗試制作一個什么都不做的函式,但它只是凍結了螢屏。有沒有辦法讓它在執行 .after 時不會修改 gui?(我嘗試了一個確實有效的函式,并且奏效了)
def doNothing():
return "nothing"
def init_timer(time=25):
global minutes
global onBreak
minutes = 0
onBreak = False
while True:
pomodoro()
def pomodoro():
global pomodoros
if pomodoros < 4:
setTimer(25)
while not(isTimerDone):
print("Timer In Progress")
setTimer(5)
while not(isTimerDone):
pomodoros = 1
else:
setTimer(30)
def timerDone():
global onBreak
global isTimerDone
isTimerDone = True
reminderTitle.config(text="The timer is done!")
onBreak = not(onBreak)
if onBreak:
reminderTitle.config(text="Go on break!")
else:
reminderTitle.config(text="Get to work!")
timer.config(text="Completed")
playsound(f'{os.getcwd()}/Audio/notification.mp3')
def setTimer(mins=25):
global isTimerDone
isTimerDone = False
timer.config(text="In Progress")
window.after(mins * 60 * 1000, timerDone)
uj5u.com熱心網友回復:
使用 while 函式時會出現此問題。因此,為了使您的程式正常作業,您必須.after僅使用,而不是在 while 函式中使用。以下是您可以基于改行程式的示例: import tkinter as tk
root = tk.Tk()
clock = tk.Label(root)
k = 0
def timing(time):
'''time in minutes'''
global k
k = time
clock.configure(text = 'you still have : ' str(time) ' minutes')
def change_value():
global k
if k > 0:
k = k-1
clock.configure(text = 'you still have : ' str(k) ' minutes')
root.after(60000,change_value)
else :
clock.configure(text = "it's over")
root.after(60000,change_value)
timing(5)
clock.pack()
root.mainloop()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/335950.html
