471,119 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Retrieving event descriptors in Tkinter

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
ka*@purdue.edu

May 8 '06 #1
2 1337
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>

May 8 '06 #2
Thanks very much. That's exactly what I was looking for. --- Avi

May 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ivan Letal | last post: by
4 posts views Thread by Christopher Subich | last post: by
reply views Thread by WaterWalk | last post: by
2 posts views Thread by Kevin Walzer | last post: by
2 posts views Thread by Kevin Walzer | last post: by
reply views Thread by John Stevens | last post: by
4 posts views Thread by skanemupp | last post: by
7 posts views Thread by gordon | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.