Re: [Tkinter-discuss] Problems with lambda functions in callbacks

2007-02-16 Thread Dídac Busquets
Hi, Thank you all for you responses. With Stewart's answer I could get it working. Those were my first lines in python (that is why I had so many semi-colons - I'm so used to C and C++). And also thanks for the explanation. One really needs to know how the programming language works when writi

Re: [Tkinter-discuss] Problems with lambda functions in callbacks

2007-02-16 Thread mkieverpy
Hello Dídac, just to add an explanation, why your code doesn't work: >from Tkinter import * > >root = Tk(); > >def cb(x): >print x; >for i in range(5): >b = Button(root,text=i,command=lambda:cb(i)); The part "lambda:cb(i)" is a function which gets evaluated (called) when a button is

Re: [Tkinter-discuss] Problems with lambda functions in callbacks

2007-02-15 Thread Bob Greschke
On Feb 15, 2007, at 08:47, Dídac Busquets wrote: > Hello, > > I'm trying to create a set of buttons to which I assign a callback > that > is the same for all of them, except for the parameter (to do this I > use > a lambda function). I want to get the buttons numbered from 0 to 4, so > that w

Re: [Tkinter-discuss] Problems with lambda functions in callbacks

2007-02-15 Thread Stewart Midwinter
Dídac, aquest és un problem molt interessant. Your code doesn't work because you didn't pass in a reference to i in your lambda. The correct code appears below. BTW, if you set up your application with classes and methods, you will need to pass in a reference to self in the same way: self=self.