I'm using Python 2 with Tkinter
and PyObjC
, and then I'm using py2app
.
The program is working fine, but the window starts as hidden whenever I open the program, so it doesn't appear until I click on the icon on the dock to bring it up.
Is there any way to control this, make the window to be on top of other windows that were open when the application is starting?
Just to clarify, it doesn't have to be on the top for the whole time the application is running. I just need it to be on top of other windows when it starts.
I got into same issue today. OSX LION 10.7.2. Add this code before
mainloop()
solves the issue.but the window always remains on top of the others until you close it. For real solve, we need to make it an app bundle, with py2app.
For OS X 10.8.3, the combination of the answers provided by vdbuilder and user2435139 did the trick for me, i.e.
called before
If I take the code you give and add the first and last line you get:
Test it. I get the window as expected. Do you get something else? If this works then somewhere in the code you are telling it to do that. If it does the same thing as your real program then your window manager is doing it. This is the best I can do without more information.
Edit:
On OSX (espicially versions using aqua) tkinter's windows may be displayed behind those that are already open (this has a bug report here: http://bugs.python.org/issue9384 but has been closed as will not fix). The addition of the
root.lift()
command has been included to bring the window to the front of the stack in those cases and is harmless in all others.I modified the above solution and these 2 lines work for me on OSX. It brings the window to the front, but without making the window behave as Always on Top.
The osascript trick Arnaud P could have problems, if there is more than one process with the application title ‘Python’; additionally, it will not work for Python 3 processes (needs to be called ‘Python3’ then.
However, I found another trick that can solve the problem by using the process id.
I know this is an old question but I found it weird that no one came up with the simple solution I had,