Listings of Events in tkinter

Event types are listed in the Tk documentation:

Virtual events are not listed there. For virtual events, check individual widget help pages.

The Tk documentation references X events, for deeper understanding of how they work:

In Tkinter, event.type contains a numeric code. You can map back from int(event.type) to the event name:

{  2: "KeyPress",
   3: "KeyRelease",
   4: "ButtonPress",
   5: "ButtonRelease",
   6: "Motion",
   7: "Enter",
   8: "Leave",
   9: "FocusIn",
   10: "FocusOut",                        
   12: "Expose",                    
   15: "Visibility",                      
   17: "Destroy",
   18: "Unmap",
   19: "Map",                     
   21: "Reparent",
   22: "Configure",                      
   24: "Gravity",
   26: "Circulate",
   28: "Property",
   32: "Colormap",
   36: "Activate",
   37: "Deactivate",
   38: "MouseWheel"
}

Tkinter matches Tk quite closely, and there's no way to get *all* bindings
for a standard widget with a single call at the Tk level (afaik).

to extract this information from a Tkinter widget, you should first call
bindtags() on the widget to get a list of binding classes used for this widget,
and you can then use bind_class(cls) to get the events for that class.

to get all events, you can use something like:

>>> from Tkinter import Button
>>> b = Button()
>>> bindings = set()
>>> for cls in b.bindtags():

...     bindings |= set(b.bind_class(cls))  # s |= t means: update set s, adding elements from t 
...
>>> bindings

set(['<Alt-KeyRelease>', '<Leave>', '<Enter>', '<KeyRelease-Alt_L>',
'<Key-Alt_R>', '<<PrevWindow>>', '<Key-F10>', '<KeyRelease-F10>',
'<Key-space>', '<Alt-Key>', '<Button-1>', '<ButtonRelease-1>',
'<KeyRelease-Alt_R>', '<Key-Tab>', '<Key-Alt_L>'])

</F>

See Also

tkinter: Events (last edited 2014-02-27 02:50:45 by sam)