Python精灵模块的Key指令

所有命令 单独命令 屏幕命令 角色命令

单独命令 >> Python精灵模块的Key指令

简介:把键盘上的按键进行实例化。Key在sprites模块中被设计为一个类。
按键列表: http://www.lixingqiu.com/2019/12/29/keylist/
例子:
from sprites import Key,Mouse,Sprite

bug = Sprite(visible=False)
bug.write('按回车键开始')

screen = bug.getscreen()
screen.listen()              # 监听按键检测

# 新建'回车'按键,(Left,Right,Down,Up,space为左右下上空格键)
enter = Key("Return")        # 新建回车键
key1 = Key('1')              # 新建数字1键
key2 = Key('2')              # 新建数字2键
key3 = Key('3')              # 新建数字3键

# 没按回车键就一直刷新
while not enter.downup():screen.update() #
bug.clear()                # 清除所写文字
bug.show()                 # 显示虫子
bug.say('按1,2,3',delay=10,wait=False)
while True:
    if key1.downup():bug.scale(1)
    if key2.downup():bug.scale(2)
    if key3.downup():bug.scale(3)     
    screen.update()
writed by lixingqiu 关注"异编程"微信公众号,获取更多关于Python精灵模块的咨讯: