Finding the widget name which generated an event

Jeff Epler jepler at unpythonic.net
Tue May 6 08:11:45 EDT 2003


What do you mean by "the name" of a widget?

If you mean, "I want to see the string 'e' or the string 'e1'", then you're
barking up the wrong tree.  If "the name" of the widget is the name of the
global variable identical to the widget, then what would it be if you wrote
	e = f = Tkinter.Entry()
?  What if there's no name for the widget because it's part of a
non-collectable but unreachable cycle?  You really don't want to think
about things in this way, trust me.

If you want to "do something" to the entry in the event, just call widget
methods on event.widget.  For instance:
	def gotFocus(event):
		event.widget.configure(bg="blue", fg="white")
	def lostFocus(event):
		event.widget.configure(bg="white", fg="black")

Jeff





More information about the Python-list mailing list