代码之家  ›  专栏  ›  技术社区  ›  torger

使tkinter窗口显示在所有其他窗口上

  •  2
  • torger  · 技术社区  · 16 年前
    #!/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()
    

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

    是否有办法使通知自动显示在所有其他窗口之上-在windows上?

    它似乎可以在linux上正常工作(ubuntu 9.10)。

    1 回复  |  直到 16 年前
        1
  •  9
  •   Peter Hansen    16 年前

    根据 this message root.overridedirect(1) . 这里的快速测试表明它应该对你有用。

    root.wm_attributes("-topmost", 1)