Re: Tkinter.Button(... command) lambda and argument problem

2006-09-16 Thread Dustan
James Stroud wrote: > Dustan wrote: > > Jay wrote: > > > >>Thanks for the tip, but that breaks things later for what I'm doing. > >> > >>[EMAIL PROTECTED] wrote: > >> > >>>In that case you don't need a lambda: > >>> > >>>import Tkinter as tk > >>> > >>>class Test: > >>>def __init__(self, paren

Re: Tkinter.Button(... command) lambda and argument problem

2006-09-16 Thread Paul Rubin
James Stroud <[EMAIL PROTECTED]> writes: > Actually, lambda is not necessary for event binding, but a closure (if > I have the vocab correct), is: ... > > def make_it(x): >def highliter(x=x): > print "highlight", x >return highliter For that version you shouldn't need the x=x: def

Re: Tkinter.Button(... command) lambda and argument problem

2006-09-15 Thread James Stroud
Dustan wrote: > Jay wrote: > >>Thanks for the tip, but that breaks things later for what I'm doing. >> >>[EMAIL PROTECTED] wrote: >> >>>In that case you don't need a lambda: >>> >>>import Tkinter as tk >>> >>>class Test: >>>def __init__(self, parent): >>>buttons = [tk.Button(parent, te

Re: Tkinter.Button(... command) lambda and argument problem

2006-09-15 Thread Dustan
Jay wrote: > Thanks for the tip, but that breaks things later for what I'm doing. > > [EMAIL PROTECTED] wrote: > > In that case you don't need a lambda: > > > > import Tkinter as tk > > > > class Test: > > def __init__(self, parent): > > buttons = [tk.Button(parent, text=str(x+1), > >

Re: Tkinter.Button(... command) lambda and argument problem

2006-09-15 Thread Jay
Thanks for the tip, but that breaks things later for what I'm doing. [EMAIL PROTECTED] wrote: > In that case you don't need a lambda: > > import Tkinter as tk > > class Test: > def __init__(self, parent): > buttons = [tk.Button(parent, text=str(x+1), > command=self.highlight(x)) for x

Re: Tkinter.Button(... command) lambda and argument problem

2006-09-15 Thread bearophileHUGS
In that case you don't need a lambda: import Tkinter as tk class Test: def __init__(self, parent): buttons = [tk.Button(parent, text=str(x+1), command=self.highlight(x)) for x in range(5)] for button in buttons: button.pack(side=tk.LEFT) def highlight(self, x)

Re: Tkinter.Button(... command) lambda and argument problem

2006-09-15 Thread Jay
Perfect. Thanks. Paul Rubin wrote: > "Jay" <[EMAIL PROTECTED]> writes: > > > I'm having a problem using lambda to use a command with an argument for > > a button in Tkinter. > > > > buttons = range(5) > > for x in xrange(5): > > > self.highlight(x)) > >

Re: Tkinter.Button(... command) lambda and argument problem

2006-09-15 Thread Paul Rubin
"Jay" <[EMAIL PROTECTED]> writes: > I'm having a problem using lambda to use a command with an argument for > a button in Tkinter. > > buttons = range(5) > for x in xrange(5): > self.highlight(x)) > buttons[x].pack(side=LEFT) > > The buttons a