如何将Tkinter窗口带到其他窗口前?

Ell*_*lan 4 python macos tkinter

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

from tkinter import *
win = Tk()
win.minsize(width=1440, height=828)
win.maxsize(width=1440, height=828)
Run Code Online (Sandbox Code Playgroud)

minsize()maxsize()使窗口覆盖我的整个屏幕,但原来的Python运行窗口(这将在一个print("Hello, World!")顶上结束).有没有办法来解决这个问题?我正在运行OS X 10.10.1.

nbr*_*bro 8

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

win.attributes('-topmost', True) # note - before topmost
Run Code Online (Sandbox Code Playgroud)

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

win.lift()
win.attributes('-topmost', True)
win.attributes('-topmost', False)
Run Code Online (Sandbox Code Playgroud)

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

关于同一问题的其他讨论: