tkinter怎么使Toplevel保持在主窗口的上面

玄隹 2014-12-27 11:09:02
我是用python的tkinter做的GUI。
在主窗口中创建了一个Toplevel窗口,然后每次我点击主窗口,Toplevel窗口就被主窗口挡在后面了,有什么地方可以设置,使得toplevel窗口永远在主窗口上面吗?
...全文
2143 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
panghuhu250 2014-12-28
  • 打赏
  • 举报
回复
这儿(http://stackoverflow.com/questions/9135302/using-python-tkinter-always-on-top-window-isnt-showing-custom-class-tooltip-t)提到的代码:

        Popup = Toplevel(root)
        Popup.resizable(0,0)
        Popup.attributes("-toolwindow", 1)
        Popup.wm_attributes("-topmost", 1)
不知道是否符合你的要求。 贴出你的代码,更容易说清楚想要哪个窗口在上面。
panghuhu250 2014-12-28
  • 打赏
  • 举报
回复
1. 这儿说它们是一样的(http://effbot.org/tkinterbook/wm.htm#wm.Wm.wm_attributes-method): attributes(*args) [#] Sets or gets window attributes. In Python 2.4, this wrapper is incomplete, and the application must use a non-standard syntax to modify and query the available attributes. Same as wm_attributes. 2. toolwindow= (Windows) If set, sets the window style to a “tool window”. Note that in this release, this attribute must be given as “-toolwindow”. 不知道“tool window”是什么,也许版本间有变化,我这儿没法测试。可以试试用attributes()不带参数,可以得到所有的attributes,看看toolwindow是否在其中。如果你不需要的话,把这句去掉也可以。
玄隹 2014-12-28
  • 打赏
  • 举报
回复
引用 1 楼 panghuhu250 的回复:
这儿(http://stackoverflow.com/questions/9135302/using-python-tkinter-always-on-top-window-isnt-showing-custom-class-tooltip-t)提到的代码:

        Popup = Toplevel(root)
        Popup.resizable(0,0)
        Popup.attributes("-toolwindow", 1)
        Popup.wm_attributes("-topmost", 1)
不知道是否符合你的要求。 贴出你的代码,更容易说清楚想要哪个窗口在上面。
谢谢,我试了一下 Popup.attributes("-topmost", 1) Popup.wm_attributes("-topmost", 1) 都可以达到窗口置顶的效果,但是不知道是不是我用的python版本不一样, Popup.attributes("-toolwindow", 1) 这句会报错。 想请问一下,你知道attributes和wm_attributes的区别是什么吗

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧