Python Notification Popup that disappears

2019-04-17 10:23发布

问题:

Is there a way to create a pop up that disappears after a certain number of seconds or minutes. I only find examples of people having trouble with popups that disappear when they are not supposed to.

I have found tkMessage box but when I test something with show info it is giving me two boxes and you have to click to get out of it. It's quite distracting.

I'd rather have something that disappears, for example, the python program see's that a new email has arrived in and then creates a pop up, which has colour and some text and not distracting. Disappearing after say 60 seconds.

回答1:

You can easily create a pop-up yourself with tkinter:

import tkinter as tk

root = tk.Tk()
root.title("info")

tk.Label(root, text="This is a pop-up message").pack()

root.after(5000, lambda: root.destroy())     # time in ms

root.mainloop()