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

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 met

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,', self.widg

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 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 everyone rea

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(roo

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('', say_hello) button1.pack() button2 = Button(root, text='Button

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('', say_hello) button1.pack() button2 = Button(root, text='Button 2') button2.bind('', say_hello) button2.pack() root.mainloop()

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: def

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 = Button(