Tkinter Puzzler

Tim Daneliuk tundra at tundraware.com
Fri Jan 7 05:28:31 EST 2005


I am trying to initialize a menu in the following manner:

for entry in [("Up", KeyUpDir), ("Back", KeyBackDir), ("Home", KeyHomeDir), ("Startdir", KeyStartDir), ("Root", 
KeyRootDir)]:

     func = entry[1]
     UI.ShortBtn.menu.add_command(label=entry[0], command=lambda: func(None))

However, at runtime, each of the menu options binds to the *last* function
named in the list (KeyStartDir).

Explicitly loading each entry on its own line works fine:

UI........command=lambda:KeyWHATEVERDir(None)

Any ideas why the first form does not fly?


TIA,
----------------------------------------------------------------------------
Tim Daneliuk     tundra at tundraware.com
PGP Key:         http://www.tundraware.com/PGP/



More information about the Python-list mailing list