Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tkinter menu question

Status
Not open for further replies.

DoraC

Programmer
May 7, 2002
98
US
Hi,

I'm very new to python/tkinter programming, and have a question.

I've managed to build a GUI that works fine (mostly). It has several menu options, one of which lists all files of a certain type in a selected directory. The code I use to set this up is:

Code:
    self.progsmenu.add_command( label   = progName,
                                underline = 0,
                                command   = 
                    lambda: self.compile(???) )

i want to pass either the progName value or the "index" of the command in question to my self.compile method. Either one would allow the compile method to know which program to compile. However, I have no idea how to figure out this information - how can I replace "???" above with either value? I've tried lots of things, and scoured the internet, but have not found any answers. Obviously, replacing "???" with "progName" doesn't work, as it isn't dynamic...

Any help tremendously appreciated!
dora c.



 
Hi,
instead of ...command= lambda: self.compile(???) ) try this:
cmd= lambda s=self,x=ix:s.compile(x)
...add_command(... command=cmd)

where ix is variable you want to pass
to self.compile function.
Bye, antjus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top