当我导入乌龟,然后尝试使用while True:
循环,它不起作用。这里的代码:虽然:不与龟一起工作
import turtle
import time
stage = turtle.Turtle()
width = 900
height = 500
def up():
turtle.setheading(90)
turtle.forward(10)
def down():
turtle.setheading(270)
turtle.forward(10)
def char():
turtle.listen()
turtle.onkey(up, 'w')
turtle.onkey(up, 's')
turtle.setup(width, height)
turtle.goto(390, 0)
char()
while True:
if (turtle.ycor() >= 250):
turtle.goto(460, 0)
stage.goto(350, 0)
turtle.done()
我不知道为什么它不工作,它只是冻结(没有响应),然后,没有错误信息。这真的很烦人,因为同样的事情发生在其他程序,我有乌龟,而真正的循环。
如果当真是问题时,有没有其他方法可以'永久检查',谢谢!
你在哪里完成'while'循环? –
当'turtle'在'(390,0)'时,为什么你会期望'turtle.ycor()> = 250',即当它的y坐标等于零? –
因为你上下移动乌龟,但是我不能,因为窗口没有响应,你用W和S移动它,当它碰到顶部时,它会回落 –