使tkinter窗口出现在所有其他窗口上

2024-10-02 22:26:52 发布

您现在位置:Python中文网/ 问答频道 /正文

#!/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上-通知不会自动弹出到所有其他当前窗口之上。你必须点击kill按钮(文本),第一次聚焦它,之后根窗口将显示在所有其他窗口的上方。在

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

它在linux上运行得很好(ubuntu9.10)。在


Tags: andfromenvbinusrwithdisplaytimeout