pmw menu item's 'command' attribute

Discussion in 'Python' started by Tina Li, Aug 28, 2003.

  1. Tina Li

    Tina Li Guest

    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! =-----
     
    Tina Li, Aug 28, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gino
    Replies:
    12
    Views:
    1,088
    Keith Wansbrough
    Sep 1, 2004
  2. Tina Li
    Replies:
    0
    Views:
    320
    Tina Li
    Sep 18, 2003
  3. Mark Light
    Replies:
    3
    Views:
    350
    Mark Light
    Jun 6, 2005
  4. MrBlueSky
    Replies:
    1
    Views:
    333
    MrBlueSky
    Jun 5, 2006
  5. Replies:
    0
    Views:
    1,498
Loading...

Share This Page