How to put a tkinter window on top of the others?

2019-01-11 04:00发布

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.

7条回答
我命由我不由天
2楼-- · 2019-01-11 04:33

More for mac OS users. Although the above solutions seem to display correctly, the app is still put at "the end of the stack" from the Finder's point of view. As can be seen with the Cmd+Tab switcher, or simply observing that python doesn't get the focus.

Solution from username fixing it all (again, for mac OS):

import os
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')

Maybe surround that with something like

import platform
if "Darwin" in platform.system():
    # apply fix
查看更多
登录 后发表回答