faqts : Computers : Programming : Languages : Python : Tkinter : Events

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 2 of 2 people (100%) answered Yes

Entry

"event.widget" and "event.type" return numerical values. How can I relate these numerical values to the name of the widget?

Aug 16th, 2000 03:29
unknown unknown, Matthew Dixon Cowles


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.