我想創建一個轉輪的動畫,並希望在while循環中有一個小的延遲,然後每次更新輪子。我已經嘗試了tkinter中的「after」函數以及python中的「sleep」函數,但是它會崩潰或完成該計算,並且只會顯示輪子轉動時沒有實際動畫的最後一個位置。雖然循環不工作在tkinter動畫
我的轉輪產生的功能:
def turning():
#initial wheel position
global position
pos(position)
#infinite loop turning the wheel
while(1):
root.after(1000, spin)
def spin():
global position
global speed
delspike() #delete current wheel
position += speed #calculate next position
if position > 360:
position -= 360
pos(position) #draw new wheel
這是爲什麼不工作?
嘗試在繪製或重繪輪子後調用'root.update_idletasks()'。 – martineau
@Pythonista:不,'while True'循環不是解決方案。它具有完全相同的不良行爲。 –