I have several widgets bound to the same function call. How do I tell which one triggered that call?
+3
A:
The event has a widget field that may help you to distinguish which widget is the source:
from Tkinter import *
class MyObj:
def callback(self, event):
print event.widget.message
obj = MyObj()
root = Tk()
btn=Button(root, text="Click")
btn.bind('<Button-1>', obj.callback)
btn.pack()
btn.message = 'Hello'
btn2=Button(root, text="Click too")
btn2.bind('<Button-1>', obj.callback)
btn2.message = 'Salut'
btn2.pack()
root.mainloop()
luc
2010-09-09 09:06:10