pmw menu item's 'command' attribute

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tina Li

    pmw menu item's 'command' attribute

    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.ad dmenuitem('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! =-----
Working...