Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Tkinter: passing parameters to menu commands (looping througha list)

Reply
Thread Tools

Re: Tkinter: passing parameters to menu commands (looping througha list)

 
 
Philippe C. Martin
Guest
Posts: n/a
 
      01-07-2005
I face a strange behavior when adding menu labels / command parameters
from a list:

***
This is the code that works but I wish to avoid - ATR and IN appear in
the menu, and __Dec is called with ATR or IN depending on the choice
***
l_dec.add_command(label = 'ATR', command= lambda: self.__Dec('ATR'))
l_dec.add_command(label = 'IN', command= lambda: self.__Dec('IN'))

***
This is the code that does not works but I wish I had - ATR and IN
appear in the menu, but __Dec is always called with the last list item
(IN in this case)

***
l_dec_list = ['ATR','IN']

for i in l_dec_list:
l_dec.add_command(label = i, command= lambda: self.__Dec(i))



Any clue ?

Regards,

Philippe


--
***************************
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***************************

 
Reply With Quote
 
 
 
 
Michael Fuhr
Guest
Posts: n/a
 
      01-07-2005
"Philippe C. Martin" <(E-Mail Removed)> writes:

> l_dec_list = ['ATR','IN']
>
> for i in l_dec_list:
> l_dec.add_command(label = i, command= lambda: self.__Dec(i))


Give the lambda an argument with a default:

l_dec.add_command(label=i, command=lambda x=i: self.__Dec(x))

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to an executable vs. passing them to a server Ramon F Herrera C++ 8 09-13-2009 02:48 AM
Re: Tkinter: passing parameters to menu commands Philippe C. Martin Python 1 01-08-2005 04:43 PM
Tkinter: passing parameters to menu commands Philippe C. Martin Python 1 01-07-2005 08:50 PM
Need Help Differentiating Bad Commands From Incomplete Commands Tim Stanka Python 1 08-02-2004 02:08 AM
Re: man pages for C commands (GCC commands) Ben Pfaff C Programming 4 06-28-2003 06:21 PM



Advertisments