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
答案 0 :(得分:0)
我会说您的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()
但是您的问题中没有足够的代码来理解全局。