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

后端 未结 7 986
北恋
北恋 2020-12-02 23:23

I\'m using Python 2 with Tkinter and PyObjC, and then I\'m using py2app.

The program is working fine, but the window starts a

7条回答
  •  猫巷女王i
    2020-12-03 00:14

    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.

    import os
    script = 'tell application "System Events" \
      to set frontmost of the first process whose unix id is {pid} to true'.format(pid=os.getpid())
    os.system("/usr/bin/osascript -e '{script}'".format(script=script))
    

提交回复
热议问题