turtle按键检测示例程序

李兴球Python海龟按键检测

"""
  turtle按键检测示例程序,程序运行后海龟不断向前移动。
  按空格键暂停或继续移动,按上下左右健改变方向
"""
import turtle

def stop_or_continue():
    global go
    go = not go

go = True
turtle.pensize(5)
turtle.color('red')
turtle.shape('turtle')
turtle.bgcolor('black')
turtle.onkeypress(stop_or_continue,"space")
turtle.onkeypress(lambda:turtle.setheading(90),"Up")
turtle.onkeypress(lambda:turtle.setheading(0),"Right")
turtle.onkeypress(lambda:turtle.setheading(-90),"Down")
turtle.onkeypress(lambda:turtle.setheading(180),"Left")

turtle.listen()

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在python, turtle分类目录。将固定链接加入收藏夹。

发表回复