每当我按空格键的时候,我都试图加快我的乌龟的速度。
我有一个代码看起来像这样
import turtle
instructions = [20,30,40,20,50,5,20,30,40,200,5]
speed = 0
wn = turtle.Screen()
drone = turtle.Turtle()
speed = 1
def sped():
global speed
speed += 1
for instruction in instructions:
drone.forward(instruction)
drone.left(45)
wn.onkey(sped, "space")
drone.speed(speed)
print(speed)
但是,速度总是1。我试着搜索互联网,但什么也没有出现。我该如何解决这个问题?
1条答案
按热度按时间yzxexxkh1#
我只需要在末尾添加wn.listen()