如何将Tkinter窗口放在其他窗口前面?

我正在使用一些Tkinter
Python代码(
Python 3.4),我遇到了一个问题.当我创建我的Tkinter窗口时,它不会显示在前面.我目前使用以下代码执行此操作:

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

minsize()和maxsize()使窗口覆盖我的整个屏幕,但是原始的python运行窗口(willprint(“Hello,World!”))最终位于顶部.有没有办法来解决这个问题?我正在运行OS X 10.10.1.

最佳答案 将它设置为最顶层(但它将始终保持在其他前面):

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

要不让它始终在其他人面前,请在mainloop之前插入此代码:

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?

点赞