I have a python3.4 script. I would like to send to the desktop a notification. How do I handle this in python? Can I use notify-send?

I'm using Ubuntu 14.04.

#in my script
if something:
  notify-send 'Here is a notification !'

You can use notify-send as an external command:

import subprocess as s

Or you can use the notify2 module (sudo apt install python3-notify2):

import notify2
n = notify2.Notification('foo', 'bar')

There are more examples included in the package (see /usr/share/doc/python3-notify2/examples/).

| improve this answer | |
  • @sgiri I thought the external lib would be better than subprocess. In either case you have to install something anyway. – Hey Jul 11 '17 at 13:33
  • @YdobEmos , subprocess is the standard library that is distributed with Python. Hence, no need to install it as a third party library. [ref: docs.python.org/2/library/index.html] – sgiri Jul 13 '17 at 15:41
  • You have to install the packet supplying notify-send. Or at least on Kubuntu you have to. Maybe it's provided by default on Ubuntu, in that case it's indeed the best solution. – Hey Jul 13 '17 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.