pmw menu item's 'command' attribute

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top