[Tkinter] messed callbacks
Giacomo Boffi
giacomo.boffi at polimi.it
Wed Sep 9 08:18:47 EDT 2009
Giacomo Boffi <giacomo.boffi at polimi.it> writes:
> ok, i'll try again following your advice
,----[ test.py ]
| from Tkinter import *
|
| def output(s):
| print s
|
| def create_cb(a,b):
| return lambda: output(a+'->'+b)
|
| def doit(fr,lst):
| for c1,c2 in zip(lst[::2], lst[1::2]):
| subframe=Frame(fr)
| Label(subframe,text=c1+' <-> '+c2).pack(side='left',expand=1,fill='both')
| Button(subframe,text='>',command=create_cb(c1,c2)).pack()
| Button(subframe,text='<',command=create_cb(c2,c1)).pack()
| subframe.pack(fill='x',expand=1)
|
| root=Tk()
| doit(root,['cyan','blue','gray','black'])
| Button(root,text='Q',command=root.destroy).pack(expand=1,fill='x')
| root.mainloop()
`----
works ok, now i have to fully understand my previous error
again, thanks you very much
g
--
Yes you who must leave everything that you cannot control.
It begins with your family, but soon it comes around to your soul.
More information about the Python-list
mailing list