[英]turtle.ontimer() equivalent for Zelle Graphics (python)?
[英]Python turtle module .ontimer loop question
def h1():
tess.forward(70)
tess.fillcolor("orange")
def h2():
tess.forward(70)
tess.fillcolor("red")
def h3():
tess.back(140)
tess.fillcolor("green")
timer = 1000
for _ in range(timer):
wn.ontimer(h1,timer)
wn.ontimer(h2, timer+1000)
wn.ontimer(h3, timer+2000)
timer +=3000
wn.listen()
wn.mainloop()
當我使用for循環時,該功能按預期工作。 當我嘗試使用while循環時,什么也沒有發生,也沒有運行時錯誤:
while True:
wn.ontimer(h1,timer)
wn.ontimer(h2, timer+1000)
wn.ontimer(h3, timer+2000)
timer +=3000
我想說您的for
循環和while
循環在啟動計時器方面都存在問題,我希望能像這樣進行更多的交接:
from turtle import Screen, Turtle
TIME = 1000 # in milliseconds
def h1():
tess.forward(70)
tess.fillcolor("orange")
screen.ontimer(h2, TIME)
def h2():
tess.forward(70)
tess.fillcolor("red")
screen.ontimer(h3, TIME)
def h3():
tess.back(140)
tess.fillcolor("green")
screen.ontimer(h1, TIME)
screen = Screen()
tess = Turtle()
h1()
screen.mainloop()
但是您的問題中沒有足夠的代碼來理解全局。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.