Ahhh, Ye Eternal Callback Questions....
:-)
THE most flexible solution I've ever used, involves
using a callback class, where there's a __call__ method
defined. That way, you create objects which can be
called, just like functions.
The nices part is that objects can carry around stuff
which you can later apply during that invocation of
the __call__ method.
A simple class like this is enough for your purposes (maybe):
class Callback:
def __init__(self, function, *args, **kwargs):
self.default_args = args
self.default_kwargs = kwargs
self.function = function
def __call__(self, *more_args, **more_kwargs):
# Create an updated argument tuple and kw-args dictionary.
more_args = self.default_args + more_args
more_kwargs.update(self.default_kwargs)
# And call the function with all this stuff.
self.function(*more_args, **more_kwargs)
# If you're not using 2.x, then:
# apply(self.function, more_args, more_kwargs)
So now, you can:
file_menu.add_command(label='Load Form',
underline=0,
command=Callback(self.open_file, FrameName, etc))
When the menu is invoked, the __call__ method of the object
you passed as argument for "command=" above is called,
which does the little mambo of calling the function you defined,
with the default parameters you defined.
Nice, eh?
-gustavo
You can't do that via any option in the add_menu method. Use
"command=lambda o=self, f=yourFrame: o.open_file(f))" or the trick I gave
in
http://groups.google.com/groups?hl=en&selm=a4alhq%246tp%241%40norfair.nerim.net
BTW, the answer to your original question (options for the add_menu method)
may be found there:
http://www.pythonware.com/library/tkinter/introduction/index.htm
(in the part "Tkinter Reference" under "Menu", but just the option names I
fear...) or there:
http://dev.scriptics.com/man/tcl8.3/TkCmd/contents.htm
if you know how to convert tcl-like syntax to Python-like syntax (usually
read "option=value" where the manual says "-option value").
HTH
- eric -