如何在Python中显示系统通知?

时间:2016-05-02 12:24:00

标签: python tkinter notifications

使用Python显示系统通知的最佳方式是什么,最好使用tkinter进行跨平台实现(我在OS X上,所以我也对可以与Notification Center集成的实现开放)?

我想展示一个自我毁灭的消息,我的意思是会在屏幕上停留几秒然后消失的方式,但不会干扰用户交互。我不想使用消息框,因为要求用户单击按钮以关闭消息窗口。

你推荐什么?

1 个答案:

答案 0 :(得分:5)

这对我有用。它将消息显示为弹出窗口,并在2秒后退出。

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