Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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()
like image 546
elegent Avatar asked Jan 21 '16 19:01

elegent


1 Answers

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.

like image 130
MattDMo Avatar answered Sep 22 '22 10:09

MattDMo