pmw menu item's 'command' attribute
Tina Li
tina_li23AThotmailDOTcom
Thu Aug 28 15:21:30 EDT 2003
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
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
More information about the Python-list
mailing list