如何将 tkinter 窗口放在其他窗口之上? [英] How to put a tkinter window on top of the others?

查看:60
本文介绍了如何将 tkinter 窗口放在其他窗口之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有 TkinterPyObjC 的 Python 2,然后我使用 py2app.

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

该程序运行良好,但是每当我打开该程序时,窗口都会以隐藏状态启动,因此在我单击 Dock 上的图标将其调出之前,它不会出现.

The program is working fine, but the window starts as hidden whenever I open the program, so it doesn't appear until I click on the icon on the dock to bring it up.

有没有办法控制这个,让窗口在应用程序启动时打开的其他窗口之上?

Is there any way to control this, make the window to be on top of other windows that were open when the application is starting?

只是为了澄清,它不必在应用程序运行的整个时间都在顶部.我只需要它在启动时位于其他窗口之上.

Just to clarify, it doesn't have to be on the top for the whole time the application is running. I just need it to be on top of other windows when it starts.

推荐答案

如果我把你给的代码加上第一行和最后一行,你会得到:

If I take the code you give and add the first and last line you get:

from tkinter import *

root = Tk() 
root.title("app")
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.geometry("550x250+%d+%d" % (screen_width/2-275, screen_height/2-125))
root.configure(background='gold')
root.lift()

mainloop()

测试一下.我按预期得到了窗口.你有别的东西吗?如果这有效,那么在代码中的某处你告诉它这样做.如果它和你的真实程序做同样的事情,那么你的窗口管理器正在做.这是我在没有更多信息的情况下所能做的最好的事情.

Test it. I get the window as expected. Do you get something else? If this works then somewhere in the code you are telling it to do that. If it does the same thing as your real program then your window manager is doing it. This is the best I can do without more information.

在 OSX(特别是使用 aqua 的版本)上,tkinter 的窗口可能会显示在那些已经打开的窗口后面(这里有一个错误报告:http://bugs.python.org/issue9384 但已关闭,因为无法修复).添加了 root.lift() 命令以在这些情况下将窗口带到堆栈的前面,并且在所有其他情况下都是无害的.

On OSX (espicially versions using aqua) tkinter's windows may be displayed behind those that are already open (this has a bug report here: http://bugs.python.org/issue9384 but has been closed as will not fix). The addition of the root.lift() command has been included to bring the window to the front of the stack in those cases and is harmless in all others.

这篇关于如何将 tkinter 窗口放在其他窗口之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆