Question: event.widget, event.type

Matthew Dixon Cowles matt at mondoinfo.com
Mon Aug 14 20:07:05 EDT 2000


On Mon, 14 Aug 2000 15:37:11 -0700, Chuck Meyers
<chuck.meyers at lmco.com> wrote:
>"event.widget", and "event.type" return numerical values.  How can I
>relate the numerical value for "event.widget" to the name of the
>widget?  How can I relate "event.type" to a name for the event?

Chuck,
event.widget isn't really a numerical value, it just prints that
way. Fredrik Lundh's excellent Introduction to Tkinter explains that
in the event attributes table at (wrapped for line length):

http://www.pythonware.com/library/tkinter/
  introduction/events-and-bindings.htm

So you can do things like:

if event.widget.widgetName=="text":

or:

if event.widget==self.textArea:

or:

event.widget.selection_clear()

As for event.type, I'm sure that you could find a list or figure them
out for yourself, but on the same page Fredrik says:

For portability reasons, you should stick to char, height, width, x,
y, x_root, y_root, and widget unless you know exactly what you're
doing...

And since I never know exactly what I'm doing <0.1 wink>, I follow his
advice carefully. But really, I've never needed the event type in
practice since I've always known what the event was since I specified
it when I bound the callback to that event. Can you give us an example
of the problem that you're trying to solve that way? There might be a
better way to solve it.

Regards,
Matt



More information about the Python-list mailing list