无法onkeyrelease()
从 Python 的 turtle 模块实现。请指教。错误信息:'module' object has no attribute 'onkeyrelease'
。turtle.onkeyrelease(stay, 'd')
尝试更换wn.onkeyrelease(stay, 'd')
无济于事。
import turtle
speed = 0
wn = turtle.Screen()
wn.tracer(0)
box = turtle.Turtle()
box.shape('square')
box.penup()
def move_right():
global speed
speed = 2
def stay():
global speed
speed = 0
turtle.listen()
turtle.onkey(move_right, 'd')
turtle.onkey(stay, 's')
turtle.onkeyrelease(stay, 'd')
while True:
wn.update()
box.setx(box.xcor() + speed)