Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread Cameron Laird
In article [EMAIL PROTECTED], Eric Brunel [EMAIL PROTECTED] wrote: On 26 Apr 2005 13:37:29 -0700, infidel [EMAIL PROTECTED] wrote: from Tkinter import Tk, Button def say_hello(event): print 'hello!' print event.widget['text'] root = Tk() button1 = Button(root, text='Button 1')

Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread tiissa
Cameron Laird wrote: In article [EMAIL PROTECTED], Eric Brunel [EMAIL PROTECTED] wrote: Unfortunately, making a binding to Button-1 on Button widgets does not have the same behavior as setting their 'command' option. Without unraveling my own confusion about who has said what to whom, does

Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread infidel
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,',

Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread Cameron Laird
In article [EMAIL PROTECTED], tiissa [EMAIL PROTECTED] wrote: . . . So far, the OP is proposed the choice to either use the event/bind mecanism or use different callbacks for his different buttons (either with the method I

Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread tiissa
Cameron Laird wrote: In article [EMAIL PROTECTED], tiissa [EMAIL PROTECTED] wrote: So far, the OP is proposed the choice to either use the event/bind mecanism or use different callbacks for his different buttons (either with the method I proposed or not). Is there general understanding that use

Re: Getting the sender widget's name in function (Tkinter)

2005-04-27 Thread Eric Brunel
On 26 Apr 2005 13:37:29 -0700, infidel [EMAIL PROTECTED] wrote: from Tkinter import Tk, Button def say_hello(event): print 'hello!' print event.widget['text'] root = Tk() button1 = Button(root, text='Button 1') button1.bind('Button-1', say_hello) button1.pack() button2 = Button(root,

Getting the sender widget's name in function (Tkinter)

2005-04-26 Thread Harlin Seritt
I have the following script. Two widgets call the same function. How can I tell inside of the called function which button called it?: def say_hello(): print 'hello!' print widget['text'] root = Tk() button1 = Button(root, text='Button 1', command=say_hello) button1.pack() button2 =

Re: Getting the sender widget's name in function (Tkinter)

2005-04-26 Thread tiissa
Harlin Seritt wrote: I have the following script. Two widgets call the same function. How can I tell inside of the called function which button called it?: As far as I know you can't (but I can be proven wrong). You may try to define a class to solve this (not tested): class say_hello:

Re: Getting the sender widget's name in function (Tkinter)

2005-04-26 Thread infidel
from Tkinter import Tk, Button def say_hello(event): print 'hello!' print event.widget['text'] root = Tk() button1 = Button(root, text='Button 1') button1.bind('Button-1', say_hello) button1.pack() button2 = Button(root, text='Button 2') button2.bind('Button-1', say_hello) button2.pack()