Desktop Notifier by Python
Contents
This article show how to send desktop notice using Python
Install requirments
we need to install notify2
by pip
1 2 3 4 5 |
# pip install notify2 Collecting notify2 Downloading notify2-0.3.1-py2.py3-none-any.whl Installing collected packages: notify2 Successfully installed notify2-0.3.1 |
Coding
First we need to import notify2
|
|
Then need to initialise the d-bus connection. D-Bus is a message bus system, a simple way for applications to talk to one another.
1 2 |
# initialise the d-bus connection notify2.init("hello") |
Next we need to create a Notification object. The simplest way is
|
|
else, you can add a icon to the notification.
|
|
next, set the urgency level for the notification.
|
|
the other available options are
|
|
next, you can decide how long will the notification will display.
use set_timeout
to set the time in milliseconds.
|
|
next, file the title and message body of the notification
|
|
notification will be shown on screen by show
method.
|
|
Try it.
|
|
and it will show up in your screen
Author Wenhan Shi
LastMod 2020-03-26 (02c19e3)