Avi Kak wrote:
Does Tkinter provide a function that returns all the event descriptors
for a given widget class? I am looking for something similar to what
you get in Perl/Tk when you call bind() with a single explicit
argument. For example, in Perl/Tk,
$widget->bind( Tk::Button )
returns a list like
<Key-Return>
<Key-space>
<ButtonRelease-1>
....
Is it possible to do the same in Tkinter? I have looked through
Fredrik Lundh's on-line reference and also the one by John Shipman. I
am unable to locate the function I need. Perhaps I have not looked hard
enough. Any help would be much appreciated.
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 the same 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:
bindings = set()
for cls in b.bindtags():
.... bindings |= set(b.bind_class(cls))
.... 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>