[Tkinter-discuss] Any way to extract from an event object the event specifier string which fired the event?

Michael Lange klappnase at web.de
Sat May 8 21:21:47 EDT 2004


On Sat, 8 May 2004 19:11:10 -0500
Kenneth McDonald <kenneth.m.mcdonald at sbcglobal.net> wrote:

> Let's say I have defined and bound a function to be executed
> in response to an event:
> 
> def callback(e):
> 	...
> 
> When the function is called, e is an event object from which I
> can extract various bits of info; for example, e.widget is the
> widget on which the binding was invoked.
> 
> However, I can't figure out any way to get the event string
> specifying the firing event, i.e. the string by which 'callback'
> was originally bound. From looking at Tk bind docs, this seems to
> be a Tk lack rather than a Tkinter lack, but I'm wondering if
> there is some other function in Tkinter/Tk which will let me
> do this.
> 
> Thanks,
> Ken
> 

That's interesting, I already asked myself the same question. Unfortunately the best
idea I had was to collect the information the event object offers and put them together to get the
event-sequence; for example I tried a little and it seems that event.type for KeyPress is 2, 
for KeyRelease 3; with event.keysym we could get the event-sequence:

def sequence(event):
    events = {'2':'KeyPress', '3':'KeyRelease'}
    return '<%s-%s>' %(events[event.type],event.keysym)

This could be very complicated if you want to catch any kind of event I'm afraid, especially if there's no documentation
about event types and everything needs to be tried first.
Maybe someone else has a better idea, if you find something please let me know, that's very interesting.

Thanks

Michael



More information about the Tkinter-discuss mailing list