Getting the sender widget's name in function (Tkinter)
infidel
saint.infidel at gmail.com
Thu Apr 28 14:35:10 EDT 2005
Here's a slight variation of tiissa's solution that gives the callable
a reference to the actual widget instead of just it's name:
from Tkinter import Tk, Button
class say_hello:
def __init__(self, widget):
self.widget = widget
def __call__(self):
print 'Hello,', self.widget['text']
def run():
root = Tk()
b1 = Button(root, text='Button 1')
b1.configure(command=say_hello(b1))
b1.pack()
b2 = Button(root, text='Button 2')
b2.configure(command=say_hello(b2))
b2.pack()
root.mainloop()
run()
More information about the Python-list
mailing list