當我導入烏龜,然後嘗試使用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移動它,當它碰到頂部時,它會回落 –