Tkinter problem on Mac OS X

Russell E. Owen rowen at cesmail.net
Mon Apr 10 16:39:59 EDT 2006


In article 
<andrew-1004061118160001 at c220-237-170-89.lowrp1.vic.optusnet.com.au>,
 andrew at trevorrow.com (Andrew Trevorrow) wrote:

> Our app uses embedded Python to allow users to run arbitrary scripts.
> Scripts that import Tkinter run fine on Windows, but on Mac OS X there
> is a serious problem.  After a script does "root = Tk()" our app's menus
> are permanently changed in the following way:
> 
> - The top item in the application menu changes to "About Tcl & Tk...".
> - The Quit item is disabled.
> - The File and Edit menus are completely replaced.
> - All further menus (except Help) are removed.
> 
> Is there a way to prevent Tkinter clobbering our app's menus?
> Or perhaps a way to restore them after the root.mainloop() call?
> 
> I've read Fredrik Lundh's excellent tutorial on Tkinter and done a lot
> of googling but haven't been able to find a solution.
> 
> I can probably add some Mac-specific code to detect a menu change after
> a script ends and then rebuild our menus, but I'm hoping there's a
> simpler Tkinter (or Tcl?) solution.

I am pretty sure it's the underlying Tcl/Tk that's causing you grief.

Does your application itself use Tcl/Tk anywhere? I'm guessing not, as 
I'd expect you'd already have gone to some trouble to get the menus 
right.

Unfortunately, I can't offer a solution. You may want to post to the 
Tkinter mailing list (via news you can use gmane, group 
gmane.comp.python.tkinter; I'm not sure if you have to sign up for the 
list before posting).

You could import Tcl/Tk yourself "up front" and then fix your 
application's menus once. But Aqua Tcl/Tk is painfully slow to start up, 
so this could really slow down startup of your own application. (Note 
that you'd have to be prepared for Tkinter to be missing (it certainly 
is by default on 10.3). You might also have to make users use one 
mainloop (see next paragraph) for this to work.

James Stroud also brings up an interesting point--that it could be 
dangerous if there are multiple scripts each trying to run their own 
mainloop. But if only one runs at a time, and cleans up after itself, 
you're probably OK. If that's not the case, you may want to start a Tk 
main loop yourself and ask users to use that loop. Again, though--it'll 
take time, and it'll only help those users who use Tkinter in their 
scripts.

-- Russell



More information about the Python-list mailing list