Retrieving event descriptors in Tkinter

A

Avi Kak

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.

Thanks.

Avi Kak
(e-mail address removed)
 
F

Fredrik Lundh

Avi said:
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(b.bind_class(cls))
....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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top