3
#!/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()

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).

torger
  • 2,308
  • 4
  • 28
  • 35

1 Answers1

9

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)
Peter Hansen
  • 21,046
  • 5
  • 50
  • 72
  • Not sure... I don't do OSX much. Just tested here with Python 2.6.5 on OSX 10.5.8, however, and get an error '''_tkinter.TclError: bad option "-topmost": must be -modified or -titlepath'''. Whatever that means. – Peter Hansen Apr 13 '11 at 01:33
  • yeah, I think this trick is windows only? Does it work on linux? – Skylar Saveland Apr 13 '11 at 02:12