![](/img/trans.png)
[英]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.