[Tkinter-discuss] command for dynamic buttons

Guilherme Polo ggpolo at gmail.com
Sat Aug 8 00:12:14 CEST 2009


2009/8/7 Guilherme Polo <ggpolo at gmail.com>:
> 2009/8/7 boivie <boivie at hotmail.com>:
...
>
> import Tkinter
>
> def test(option):
>    print option
>
> things = ['a', 'b', 'c', 'd']
>
> root = Tkinter.Tk()
>
> for indx, option in enumerate(things):

You don't need indx neither enumerate here (same for the gtk code). I
was going to use grid like you did, but in the end the pasted code
didn't use. I hope this doesn't compromise understanding the problem
described.

>    cmd = lambda opt=option: test(opt)
>    btn = Tkinter.Button(text=option, command=cmd)
>    btn.pack(side='left')
>
> root.mainloop()



-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list