如何让Tkinter窗口跳到前面?

如何让Tkinter窗口跳到前面?

如何让Tkinter应用程序跳到前面?目前,窗口出现在我所有其他窗口后面,并没有得到焦点。

我应该打电话给我一些方法吗?


绝地无双
浏览 1372回答 3
3回答

互换的青春

当您说“我的其他窗口”时,假设您的意思是您的应用程序窗口,您可以lift()在Toplevel或Tk上使用该方法:root.lift()如果您希望窗口保持在所有其他窗口之上,请使用:root.attributes("-topmost", True)root你的Toplevel或Tk 在哪里?别忘了-面前"topmost"!要使其成为临时,请在以下后禁用最顶层:def raise_above_all(window):     window.attributes('-topmost', 1)     window.attributes('-topmost', 0)只需传入你想要引发的窗口作为参数,这应该可行。

慕码人8056858

如果您在Mac上执行此操作,请使用AppleEvents将重点放在Python上。例如:import os os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')

一只名叫tom的猫

在mainloop()之前添加以下行:root.lift()root.attributes('-topmost',True)root.after_idle(root.attributes,'-topmost',False)它对我来说很完美。当窗口生成时,它会使窗口显示在前面,并且它不会始终位于前面。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python