如何将 Tkinter window 置于其他 windows 之前?

How to bring Tkinter window in front of other windows?

我正在使用一些 Tkinter Python 代码 (Python 3.4),我遇到了一个问题。当我创建我的 Tkinter window 时,它没有出现在前面。我目前使用以下代码进行操作:

from tkinter import *
win = Tk()
win.minsize(width=1440, height=828)
win.maxsize(width=1440, height=828)

minsize()maxsize() 让 window 覆盖了我的整个屏幕,但是原来的 python 运行 window (那个那将 print("Hello, World!")) 最终排在首位。有没有办法来解决这个问题?我是 运行 OS X 10.10.1.

将它设置为最顶层(但它总是在其他人的前面):

win.attributes('-topmost', True) # note - before topmost

为了不让它总是在其他人面前,在主循环之前插入这段代码:

win.lift()
win.attributes('-topmost', True)
win.attributes('-topmost', False)

不要忘记代码末尾的 win.mainloop()(即使在某些情况下没有明确要求)

同一问题的其他讨论:

  • How to put a Tkinter window on top of the others

  • How to make a Tkinter window jump to the front?