T
Tina Li
Hello,
I'm new to Python and pmw, and I might be missing something obvious,
but...say I created a cascade menu 'Size' and am adding menu items:
for size in ('tiny', 'small', 'average', 'big', 'huge'):
self.menuBar.addmenuitem('Size', 'command', 'Set size to ' +
size,
command = lambda: cmd.do('change size ' + size),
label = size)
where cmd is a class executing the command string being passed in. The
labels show up correctly, but when I click on any of the size items, the
command is always
change size huge
So it seems that when the lambda function is assigned to 'command' as a
function reference, the argument string isn't evaluated right away. When
cmd.do, the variable 'size' is then looked up, which stays at 'huge' in the
end.
I don't know if I've understood things correctly. In any case, is there a
way to make it do what it's supposed to do (i.e. the commands correspond to
the their individual size label)?
Thanks in advance!
Tina
I'm new to Python and pmw, and I might be missing something obvious,
but...say I created a cascade menu 'Size' and am adding menu items:
for size in ('tiny', 'small', 'average', 'big', 'huge'):
self.menuBar.addmenuitem('Size', 'command', 'Set size to ' +
size,
command = lambda: cmd.do('change size ' + size),
label = size)
where cmd is a class executing the command string being passed in. The
labels show up correctly, but when I click on any of the size items, the
command is always
change size huge
So it seems that when the lambda function is assigned to 'command' as a
function reference, the argument string isn't evaluated right away. When
cmd.do, the variable 'size' is then looked up, which stays at 'huge' in the
end.
I don't know if I've understood things correctly. In any case, is there a
way to make it do what it's supposed to do (i.e. the commands correspond to
the their individual size label)?
Thanks in advance!
Tina