83

In Python tkinter module, <Button-1>, <Button-2> and <Button-3> are used to identify mouse button clicks for left, middle and right buttons respectively.

Likewise, <KeyPress-Return> is used for the return key press.

Where can I find a list of all such events, including the names for the various keyboard keys?

Tcl bind manual does not have those.

Braiam
  • 1
  • 11
  • 47
  • 78
mcu
  • 3,302
  • 8
  • 38
  • 64

4 Answers4

125

A general list for Bindings and Events can be found on effbot.org or in the docs provided by New Mexico Tech whereas the name of several keys are listed here in addition to the original documentation.

Here's a summary of the most common events with some keypress names explained:

Event Description
<Button-1>

Button 1 is the leftmost button, button 2 is the middle button(where available), and button 3 the rightmost button.

<Button-1>, <ButtonPress-1>, and <1> are all synonyms.

For mouse wheel support under Linux, use Button-4 (scroll up) and Button-5 (scroll down)

<B1-Motion> The mouse is moved, with mouse button 1 being held down (use B2 for the middle button, B3 for the right button).
<ButtonRelease-1> Button 1 was released. This is probably a better choice in most cases than the Button event, because if the user accidentally presses the button, they can move the mouse off the widget to avoid setting off the event.
<Double-Button-1> Button 1 was double clicked. You can use Double or Triple as prefixes.
<Enter> The mouse pointer entered the widget (this event doesn't mean that the user pressed the Enter key!).
<Leave> The mouse pointer left the widget.
<FocusIn> Keyboard focus was moved to this widget, or to a child of this widget.
<FocusOut> Keyboard focus was moved from this widget to another widget.
<Return> The user pressed the Enter key. For an ordinary 102-key PC-style keyboard, the special keys are Cancel (the Break key), BackSpace, Tab, Return(the Enter key), Shift_L (any Shift key), Control_L (any Control key), Alt_L (any Alt key), Pause, Caps_Lock, Escape, Prior (Page Up), Next (Page Down), End, Home, Left, Up, Right, Down, Print, Insert, Delete, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, Num_Lock, and Scroll_Lock.
<Key> The user pressed any key. The key is provided in the char member of the event object passed to the callback (this is an empty string for special keys).
a The user typed an "a". Most printable characters can be used as is. The exceptions are space (<space>) and less than (<less>). Note that 1 is a keyboard binding, while <1> is a button binding.
<Shift-Up> The user pressed the Up arrow, while holding the Shift key pressed. You can use prefixes like Alt, Shift, and Control.
<Configure> The widget changed size (or location, on some platforms). The new size is provided in the width and height attributes of the event object passed to the callback.
<Activate> A widget is changing from being inactive to being active. This refers to changes in the state option of a widget such as a button changing from inactive (grayed out) to active.
<Deactivate> A widget is changing from being active to being inactive. This refers to changes in the state option of a widget such as a radiobutton changing from active to inactive (grayed out).
<Destroy> A widget is being destroyed.
<Expose> This event occurs whenever at least some part of your application or widget becomes visible after having been covered up by another window.
<KeyRelease> The user let up on a key.
<Map> A widget is being mapped, that is, made visible in the application. This will happen, for example, when you call the widget's .grid() method.
<Motion> The user moved the mouse pointer entirely within a widget.
<MouseWheel> The user moved the mouse wheel up or down. At present, this binding works on Windows and MacOS, but not under Linux.
<Unmap> A widget is being unmapped and is no longer visible.
<Visibility> Happens when at least some part of the application window becomes visible on the screen.
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
albert
  • 8,027
  • 10
  • 48
  • 84
  • 2
    Not all keysyms are listed there. The low-level stuff can always come up with keysyms we've never heard of. Sometimes, you end up having to just try it and see. – Donal Fellows Aug 29 '15 at 20:28
  • 2
    latest tcl8.7 documents: https://tcl.tk/man/tcl8.7/TkCmd/keysyms.html – moogoo Aug 31 '21 at 01:42
  • 1
    @moogoo, bare in mind that, as of today, Tcl/Tk 8.7 is [still in alpha development](https://tcl.tk/software/tcltk/8.7.html) and, therefore, is unlikely to be embedded in Python, on the contrary to Tcl/Tk 8.6. For the link to Tcl/Tk 8.6 documentation, see [this answer](https://stackoverflow.com/a/72087813/7009806). – Olivier Jan 13 '23 at 03:08
  • Most events correspond to an XEvent with a suspiciously similar name. – Donal Fellows Jun 19 '23 at 15:27
  • Also, if you're doing text input then be aware that input methods and assistive technologies produce "key" events without a corresponding keysym but with non-empty text. The default widget class bindings should handle this for you (except for canvases). – Donal Fellows Jun 20 '23 at 07:45
6

Try looking at the definition of class EventType in the source code for the module tkinter/__init__.py.

Typically for me, this modules shows up as a tab in my Wing IDE if an exception occurs.

martineau
  • 119,623
  • 25
  • 170
  • 301
dday52
  • 61
  • 1
  • 2
  • 8
    Can you please elaborate on your answer? For instance, you should provide an example as to how these tools can help solve the problem, or at least links to further documentation. – Richard-Degenne Aug 16 '19 at 16:26
3

The comprehensive list of all symbols recognised by current tkinter (which bundles Tcl/Tk 8.6 threaded, as of when I'm writing this) can be found here.

Olivier
  • 303
  • 3
  • 14
0

There is a little Tkinter-Help-Tool on Github, where you can analyse any event, including the data for event.keysym_num and event.state as bitmask!

KEYSYM_NUM: 65 | STATE MASK: 2 == 0x2 == 0b10

Maybe it helps to solve your problem.

squawk7x
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '23 at 06:12