[Tkinter-discuss] Tkinter Windows don't appear under MacOSX Lion

Michael O'Donnell michael.odonnell at uam.es
Wed May 23 11:11:32 CEST 2012

Dear all,

  I use py2app to package my python 2.7.2 program into a distributable.

  My previously working application seems not to work under MacOSX Lion,
windows (the root window, and Toplevel windows) until I use apple-tab
to cycle in and then back to the application.

I have seen numerous other complaints of this. , e.g.,

However, these address the main window not appearing on duble
clicking the application. What concerns me more is that it seems
to apply also to Toplevel windows created within an application.

I really don't want to search through the 1000s of lines of my code
to find all places where some sort of toplevel (or subclass thereof)
is created, insert some hack code which forces the window to appear,
given this is a problem that only affects my program on Macs, and then
only in Lion.

Rather, I would rather understand what is going on, and whether there
is perhaps a general fix.

Firstly, I note that this only affects me on Mac, and only on Lion.
Also, it does not affect my code when run under idle, or when I run my
directly using python. It only happens with a py2app application.

For instance, I use the following code in a file called 'test.py':

from Tkinter import *
tk = Tk()

fr=Frame(tk, height=400, width=400)


def openWin():
    Button(t, text="Close", command=lambda w=t: w.destroy()).pack()

for i in range(4):
    for j in range(4):
        Button(fr, text="Open", command=openWin).grid(row=i, column=j)


Then I use py2app to make an application, e.g.,

from setuptools import setup
import sys
    options={'py2app': {'argv_emulation': True, 'resources': []}},

This makes an application, test.app, which, when double clicked,
brings up the application menubar, but no window. If I apple-tab
and then apple-tab again (to return to this app), the window appears.

Clicking on buttons does NOT open the Toplevel window which should
appear (but the window will apear if I cycle in and out of the app). Also
if I click multiple buttons, each of the toplevel windows is listed in the
list of windows associated with the app (visible by clicking on the app's
icon in the doc).

Now, after much experimentation, I find if I put a grab_set() in the
code (uncommenting line 3 in the test.py), then at least the
toplevels appear as expected.

Does anyone have any idea why this is so? Why is this line
only needed on Lion?

Does this happen the same on your macs?

I would like to know, as my code may change the grab_set somewhere
in the code and stop things working (hard to tell in the spagetti
of my program).

(using ActivePython (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:20:15)  Tk 8.5



Not sent from my iPhone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20120523/127c82be/attachment.html>

More information about the Tkinter-discuss mailing list