Tkinter: passing parameters to menu commands (looping through a list)

Philippe C. Martin philippecmartin at sbcglobal.net
Fri Jan 7 09:34:40 EST 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
***************************




More information about the Python-list mailing list