Finding the widget name which generated an event

Python-lover hemanexp at yahoo.com
Tue May 6 06:31:42 EDT 2003


Hi,
   how can i find the widget name that generated an
event? I have placed 2 entry widgets in my window and
bind "FocusIn","FocusOut" events to those entry boxes.
In the event handler i want to print the name of the
entry widget that generated the event. I tried with
event.widget. But i got an instance number of the
widget rather than widget name. How can i get the
widget name that generated an event?
My coding is given below.

import Tkinter
def gotFocus(event):
	print 'Focus in',' Widget: ',event.widget
def lostFocus(event):
	print 'Focus out',' Widget: ',event.widget

root = Tkinter.Tk()

e = Tkinter.Entry()
e1=Tkinter.Entry()

e.bind('<FocusIn>', gotFocus)
e.bind('<FocusOut>', lostFocus)
e1.bind('<FocusIn>', gotFocus)
e1.bind('<FocusOut>', lostFocus)
e.pack()
e1.pack()
root.mainloop()

Thanx

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list