pythontkinternotifications

How to display a system notification in Python?


What is the best way to display system notifications with Python, preferably using tkinter for cross platform implementation (I am on OS X, so I'm also open to implementations that would allow integration with Notification Center)?

I want to show a self-destroying message, I mean something that would remain on screen for a few seconds and then would vanish way, but without interfering with user interaction. I don't want to use a messagebox because in requires the user to click in a button to dismiss the message window.

What do you recommend?


Solution

  • This works for me. It shows the message as a popup and exits after 2 seconds.

    from tkinter import *
    from sys import exit
    def popupError(s):
        popupRoot = Tk()
        popupRoot.after(2000, exit)
        popupButton = Button(popupRoot, text = s, font = ("Verdana", 12), bg = "yellow", command = exit)
        popupButton.pack()
        popupRoot.geometry('400x50+700+500')
        popupRoot.mainloop()