是否有海龟图形使用的关键事件名称的完整列表? [英] Is there a complete list of key event names used by turtle-graphics?

查看:26
本文介绍了是否有海龟图形使用的关键事件名称的完整列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Python 的 Turtle 模块时,我使用了一些关键事件,如官方文档所述:><块引用>

turtle.onkey(fun, key)

参数:

  • fun – 一个没有参数或 None 的函数
  • key – 字符串:键(例如a")或键符号(例如空格")

现在有趣的是,当您调用 1) onkeyrelease() 方法并传递一个未注册的字符串(如空字符串 ("") 或 "+" 等)作为 key 参数:

turtle.onkeyrelease(lambda: print("Got key event while listen to none."), "")

无论用户按下什么键,程序都会输出Got key event ...",顺便说一下这个问题.

很遗憾,我无法在 Internet 其他地方的文档中找到有关此行为的更多信息.所以我想知道是否有一个完整的列表,列出了用于编程关键事件的所有支持的 key-name-strings?

<小时>

1) 问题中使用的基本设置:

导入海龟龟.setup(700,500)海龟窗口 = 海龟.屏幕()turtleWindow.onkey(lambda: print("你按下了 'a'"), "a")海龟窗口.listen()

解决方案

我浏览了 turtle.py 来源并得出与 mgc,密钥是 tkinter 的一部分,而不是 turtle.不想通读整个 tkinter 源代码,我做了一些谷歌搜索,发现了这个 Tk 文档中的完整键符列表,以及此 缩写列表,用于 Latin-1 键盘(它缺少单个字母,但它们也是有效的键标识符,例如 "Q"代码>).我不确定它们是否区分大小写,因此您必须进行一些实验.

While playing around with Python's Turtle module, I used some key events as the official documentation states:

turtle.onkey(fun, key)

Parameters:

  • fun – a function with no arguments or None
  • key – a string: key (e.g. "a") or key-symbol (e.g. "space")

Now the interesting thing is that when you call 1) the onkeyrelease() method and pass a not registered string (like an empty one (""), or "+", etc.) as key parameter:

turtle.onkeyrelease(lambda: print("Got key event while listening to none."), "")

No matter what key is pressed by the user, the program outputs "Got key event ...", which was by the way the problem in this question.

Unfortunately I can't find more information about this behavior in the documentation ore elsewhere on the internet. So I wonder if there is a complete list of all supported key-name-strings used to program key events?


1) The basic setup used in the question:

import turtle
turtle.setup(700,500)
turtleWindow = turtle.Screen()
turtleWindow.onkey(lambda: print("You pressed 'a'"), "a")
turtleWindow.listen()

解决方案

I scanned through the turtle.py source and came to the same conclusion as mgc, that the keys are part of tkinter, not turtle. Not wanting to read through the entire tkinter source, I did some googling and found this full list of keysyms in the Tk docs, as well as this abbreviated list for Latin-1 keyboards (it is missing the individual letters, but they are also valid key identifiers, such as "Q"). I'm not sure if they are case-sensitive or not, so you'll have to do some experimentation.

这篇关于是否有海龟图形使用的关键事件名称的完整列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆