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
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
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
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),
> >
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
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)
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))
> >
"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