
""" 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() while 1: turtle.fd(go*1) turtle.update()
本站所有作品,教程等皆为原创,版权所有。只供个人及单位内部研究使用,对外展示或传播必需经本站同意,且注明来自本站。培训机构等用本站资源培训学生,需经本站授权。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。入住QQ群:225792826 和爱好者共同交流,并且能下载免费提供的Python资源(需提供真实姓名才可入群)
李兴球的博客_Python创意编程技术前沿_pygame » turtle按键检测示例程序
李兴球的博客_Python创意编程技术前沿_pygame » turtle按键检测示例程序