Tkinter menu

gh14tq5 at yahoo.com gh14tq5 at yahoo.com
Fri Dec 2 18:57:26 EST 2005


> 
> the easiest way to do this is to create a new function object for each
> file, and use default argument binding to pass in the right filename:
> 
>     for file in self.allfiles:
>         def callback(fname=file):
>             self.showFile(fname, parent)
>         self.showfilemenu_bar.addmenuitem('Show Files',
>             'command',label=file, command=callback)
> 
> the "def" statement creates a new instance of the callback function for
> each iteration.  the "fname" variable is bound to the current file object,
> while "self" and "parent" are bound to the variables with the same names
> in the outer scope.
> 
> </F>
> 

That was exactly what I was looking for.  It worked perfectly. Thanks.

John




More information about the Python-list mailing list