我试着用python建立一个简单的海龟程序,我可以通过按下空格键来移动海龟,它一直在移动,直到我再次碰到空格键。我可以让他用太空出版社移动固定的距离,但不能让它继续下去。在
以下是我的工作:from turtle import *
# PUT YOUR CODE HERE
setup(800,600)
home()
pen_size = 2
color("blue")
title("Turtle")
speed("fastest")
drawdist= 25
current_state = penup
next_state = pendown
#Button Instructions
def move_up():
seth(90)
forward(drawdist)
def move_down():
seth(270)
forward(drawdist)
def move_left():
seth(180)
forward(drawdist)
def move_right():
seth(0)
forward(drawdist)
def space_bar():
seth(90)
forward(drawdist)
global current_state, next_state
next_state()
current_state, next_state = next_state, current_state
#Change Pen Color
def red():
color("red")
def green():
color("green")
def blue():
color("blue")
#Button Triggers
s= getscreen()
s.onkey(move_up,"Up")
s.onkey(move_down,"Down")
s.onkey(move_left,"Left")
s.onkey(move_right,"Right")
s.onkey(space_bar,"space")
s.onkey(red,"r")
s.onkey(green,"g")
s.onkey(blue,"b")
listen()
done()