On Sun, 27 Feb 2005 16:06:32 -0000, Alan Gauld <[EMAIL PROTECTED]> 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 > the > > idea of an id or identifier - I can't see that here. Ideally, I > would > > 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: > self.showButton(n)) > b.rid(column=4, row=i+4) > submitlist.append(b) > > 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!) > > HTH, > > Alan G > Author of the Learn to Program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld
Yay! Thanks for the tips Michael/Alan - works a treat, although I must admit, I'm not sure what Lambda does. Adam -- http://www.monkeez.org PGP key: 0x7111B833 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor