如何使用 Python 3 发送桌面通知?

Tot*_*oum 12 python notify-send python3

我有一个 python3.4 脚本。我想向桌面发送通知。我如何在python中处理这个?我可以使用通知发送吗?

我正在使用 Ubuntu 14.04。

#in my script
if something:
  notify-send 'Here is a notification !'
Run Code Online (Sandbox Code Playgroud)

mur*_*uru 23

您可以notify-send用作外部命令:

import subprocess as s
s.call(['notify-send','foo','bar'])
Run Code Online (Sandbox Code Playgroud)

或者您可以使用notify2模块 ( sudo apt install python3-notify2):

import notify2
notify2.init('foo')
n = notify2.Notification('foo', 'bar')
n.show()
Run Code Online (Sandbox Code Playgroud)

包中包含更多示例(请参阅 参考资料/usr/share/doc/python3-notify2/examples/)。