Is there a complete list of key event names used by turtle-graphics?

社会主义新天地 提交于 2019-12-14 01:50:34

问题


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()

回答1:


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.



来源:https://stackoverflow.com/questions/34932365/is-there-a-complete-list-of-key-event-names-used-by-turtle-graphics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!