开发者

Make a tkinter window appear over all other windows

#!/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 appl开发者_如何转开发iction
    root.after(timeOut,root.destroy)
    root.mainloop()

The above code creates a notification, with a timout. However on windows - the notification does not automatically pop up above all other present windows automatically. One has to click on the kill button (the text), and focus it the first time, after which the root window will be displayed above all other windows.

Is there a way to make the notification automatically appear above all other windows - on windows?

It seems to work on linux just fine (ubuntu 9.10).


According to this message you should be able to add the following after root.overridedirect(1). A quick test here suggests it should work for you.

root.wm_attributes("-topmost", 1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜