List of All Tkinter Events

List of All Tkinter Events

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:







































































































EventDescription
<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).
aThe 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.

Master list of all Tkinter Events?

There is no such list as far as I know. There is a list of most events on the bind man page, but each widget can itself issue events unique to that widget (eg: <<ListboxSelect>>). Those are documented on the man page for each widget.

Tkinter REALLY ALL Complete Event List

No, there is no function that converts 2 to <KeyPress>. And no, it's not a sick joke by the tkinter team. That sort of information simply isn't necessary, or particularly useful.

List of Sequences Available for Each TKinter Widget

You can use this code to get events for some widget (except virtual events):

from itertools import chain
def get_events(widget):
return set(chain.from_iterable(widget.bind_class(cls) for cls in widget.bindtags()))

root = Tk()
a = get_events(Button())
print(a)
root.destroy()

>>> {'<KeyRelease-Alt_R>', '<Enter>', '<Key-space>', '<Button-1>', '<Key-Alt_R>', '<KeyRelease-F10>', '<<PrevWindow>>', '<Alt-Key>', '<Alt-KeyRelease>', '<ButtonRelease-1>', '<Leave>', '<KeyRelease-Alt_L>', '<Key-Alt_L>', '<Key-F10>', '<Key-Tab>'}

And links: Master list of all Tkinter Events?

Is there a click event handler in tkinter?

You can add a click event to a canvas.

Something like this should work:

root = Tk()

def on_click(event):
print("you clicked")

canvas = Canvas(root, width=800, height=600)
canvas.bind("<Button-1>", on_click)
canvas.pack()

# Canvas.focus_set is required if the window already contains a widget that has keyboard/input focus
canvas.focus_set()

root.mainloop()

Here are some examples of using this method: https://python-course.eu/tkinter/events-and-binds-in-tkinter.php

Tkinter difference between event and event

Bindings that have a single set of brackets are built-in events directly supported by the underlying OS. Examples include <KeyPress>, <ButtonPress-1>, <Configure>, and many more. Most of the built-in events are directly tied to actual physical events such as pressing a mouse button or key on the keyboard.

Bindings with double-brackets are called virtual events. They do not necessarily represent any sort of physical event, and typically (though not always) are unique to specific widgets. For example, <<ListboxSelect>> is only used by the listbox, <<NotebookTabChanged>> is only used by the ttk notebook, and so on.

Virtual events can be triggered by a combination of other events using the event_add widget method, though they can also be generated by calling event_generate.

The tcl/tk man pages includes a list of predefined virtual events.



Related Topics



Leave a reply



Submit