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., http://stackoverflow.com/questions/9083687/python-tkinter-gui-always-loads-minimized http://stackoverflow.com/questions/8691655/python-put-window-on-top-tkinter-pyobjc http://www.velocityreviews.com/forums/t593134-tkinter-osx-and-lift.html 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 script 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) fr.pack() #tk.grab_set() def openWin(): t=Toplevel(tk) 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) tk.iconify() tk.update() tk.deiconify() tk.lift() tk.mainloop() Then I use py2app to make an application, e.g., from setuptools import setup import sys sys.argv=[sys.argv[0]] sys.argv.append("py2app") setup( app=['test.py'], data_files=[], options={'py2app': {'argv_emulation': True, 'resources': []}}, setup_requires=['py2app'], ) 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 2.7.2.5 (ActiveState Software Inc.) based on Python 2.7.2 (default, Jun 24 2011, 12:20:15) Tk 8.5 Mick -- Not sent from my iPhone
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss