Duncan Booth duncan at
Thu May 24 05:38:11 EDT 2001

Laura Creighton <lac at> wrote in
news:mailman.990635563.6483.python-list at 
> If I had just used w.grid up there I would get a yellow button with
> pink text.   This form is concise.  What do the lambda dislikers
> suggest I do instead?  (This is a serious question)

If you are using Python 2.1, then the lambda form becomes much neater:

from __future__ import nested_scopes
import Tkinter

if __name__ == '__main__':
    root = Tkinter.Tk()
    w = Tkinter.Button(root, text='This is a very green button', width= 30, 
    buttonList = (
        ['show', lambda: w.grid(row=0, col=0, columnspan= 5)],
        ['pink', lambda: w.configure(fg='pink')],
        ['yellow', lambda: w.configure(bg='yellow')],
        ['Exit', root.destroy],
    column = 0
    for txt, cmd in buttonList:
        button = Tkinter.Button(root, text = txt, command = cmd)
        button.grid(row=1, col=column, sticky = 'w')
        column = column + 1

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list