[Tutor] Recursive Tkinter buttons
kabads at gmail.com
Sun Feb 27 20:32:27 CET 2005
On Sun, 27 Feb 2005 16:06:32 -0000, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
> > - however, when I click the button, I want self.showButton to know
> > which one of them was pressed. I've seen in other gui programming
> > idea of an id or identifier - I can't see that here. Ideally, I
> > like to know the value of i in self.showButtons - but when I use
> > self.showButtons(i) showButtons gets called straight at run time.
> The easy way to do this is to use a defrault parameter in a lambda:
> submittext = ">>> "
> for i in range (1, 11):
> b = Button(text=submittext, command = lambda n=i:
> b.rid(column=4, row=i+4)
> Notice the button creation line now uses a lambda with default
> parameter set to i. That lambda calls your method but now passes
> in the value of i for that button. (You need to modify your method
> to accept that value of course!)
> Alan G
> Author of the Learn to Program web tutor
Yay! Thanks for the tips Michael/Alan - works a treat, although I must
admit, I'm not sure what Lambda does.
PGP key: 0x7111B833
More information about the Tutor