【问题标题】:Make a tkinter window appear over all other windows使 tkinter 窗口出现在所有其他窗口之上
【发布时间】:2010-12-27 11:40:43
【问题描述】:
#!/usr/bin/env python
# Display window with toDisplayText and timeOut of the window.

from Tkinter import *

def showNotification(notificationTimeout, textToDisplay):

    ## Create main window
    root = Tk()
    Button(root, text=textToDisplay, activebackground="white", bg="white", command=lambda: root.destroy()).pack(side=LEFT)

    root.update_idletasks()
    # Remove window decorations
    root.overrideredirect(1)

    timeOut = int(notificationTimeout*1000) # Convert to ms from s

    ## Run appliction
    root.after(timeOut,root.destroy)
    root.mainloop()

上面的代码创建了一个带有超时的通知。但是在 Windows 上 - 通知不会自动弹出所有其他当前窗口的上方。必须单击终止按钮(文本),第一次将其聚焦,之后根窗口将显示在所有其他窗口之上。

有没有办法让通知自动出现在所有其他窗口上方 - 在窗口上?

它似乎在 linux 上运行得很好(ubuntu 9.10)。

【问题讨论】:

    标签: python windows focus stack tkinter


    【解决方案1】:

    根据this message,您应该可以在root.overridedirect(1) 之后添加以下内容。此处的快速测试表明它应该适合您。

    root.wm_attributes("-topmost", 1)
    

    【讨论】:

    • 不确定...我不经常使用 OSX。但是,刚刚在 OSX 10.5.8 上使用 Python 2.6.5 进行了测试,得到了错误 '''_tkinter.TclError: bad option "-topmost": must be -modified or -titlepath'''。不管那意味着什么。
    • 是的,我认为这个技巧只适用于 Windows? linux下能用吗?
    猜你喜欢
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    相关资源
    最近更新 更多