473,735 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter problem on Mac OS X

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.

Andrew
Apr 10 '06 #1
2 5195
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.

Andrew


This menu mashing is a problem. This really has nothing to do with
programing in Tcl, Tk, Python, or Tkinter. First of all, the "About Tcl
& Tk" is hard-wired during the build of Aqua Tk. To fix this will
require downloading the sources and building your own Aqua Tk from
scratch: http://tcltkaqua.sourceforge.net/8.4.10/

Alternatively, you can res-edit the appropriate files. The "About Tcl &
Tk" menu item is held in an rsrc file. I forget exactly where, but I can
take a look on my ibook if you are interested in this route. To do this,
you will want a working copy of resknife. I had some trouble with it, so
I had to build it for my ibook with xcode--IIRC, the build I downloaded
had problems saving. Getting the source and building on my computer
fixed it. Its a great program.

I'm guessing the best way to get around destroying your menus is to
intercept calls to Tk(). I've had bad luck with multiple Tk() instances
running in the same session (this is the case with EVERY implementation
of Tkinter I've seen, Linux, Mac, etc.). StringVar and IntVar instances
get very screwy with multiple Tk()s. You might want to re-define Tk() to
return the root instance created by your program. Also, knew Toplevel()s
will have their own menus, resulting in your application's menus
becoming replaced while the Toplevel() is in the foreground, that's just
how Aqua Tk works. This may be something you have to live with if you
want your students (I'm guessing) to learn about python in your environment.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Apr 10 '06 #2
In article
<an************ *********@c220-237-170-89.lowrp1.vic.o ptusnet.com.au> ,
an****@trevorro w.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.pyth on.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
Apr 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5981
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
3
7035
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter import * class App:
1
2976
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the scroll-bars work as advertised. That's great. However, if you click the Left Mouse button, it calls code which expands the width of the canvas by 100 pixels. The area being viewed expands correspondingly..... BUT I DON'T WANT IT TO!!
0
3587
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the...
1
3598
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
3
3611
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it yesterday), so I am sure I am overlooking something simple. The basic idea is that my application will consist of a series of modal dialogs, that are chained together in "wizard" fashion. There will be some processing in between dialogs, but for the most...
1
5249
by: yvesd | last post by:
hello i want to intercept tkinter python system events like wm_delete_window and if possible for any window, but the newest code I've produced give me an error : Traceback (most recent call last): File "C:\Documents and Settings\yvesd\Bureau\protowin.py", line 36, in ? b1 = Tkinter.Button (win1)
8
3287
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to my pc. But, it is not getting installed and is failing by throwing the below errors. Should i need to configure / install any specific files for resolving this issue ?
3
2983
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I guess my question is two-fold. 1) How do I get rid of that window? 2) Any comments in general? I am just learning python (and coding with classes), so I'm sure there are things I should pound into my head before I learn bad habits. Here's the...
3
3918
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By this I mean that the format would be something like this: You have Page1 : This has 2-3 buttons on it. Clicking on each button opens up a new window respectively having
0
8786
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9466
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9201
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6049
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4564
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2190
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.