DEV Community

Cover image for DIY Desktop Notifications with Python
Techelopment
Techelopment

Posted on • Edited on

2

DIY Desktop Notifications with Python

Creating a python script for a “do it yourself” reminder is very easy! The player library is all we need 🙂

First let's install the library:



pip install plyer


Enter fullscreen mode Exit fullscreen mode

Before moving on to our reminder script, let's take a look at the notification module that will allow us to generate a notification.

The import of the notification module is done like this:



from plyer import notification


Enter fullscreen mode Exit fullscreen mode

The function to use will be notification.notify, its main parameters are (full docs here):



title (str) - Title of the notification 
message (str) - Message contained within the notification 
app_name (str) - Name of the application 
app_icon (str) - Icon to display next to the notification message 
timeout (int) - Time to display the notification in seconds (default 10) 
ticker (str) - Text to display in the notification bar


Enter fullscreen mode Exit fullscreen mode

We are ready

Now that everything is configured and described, we are ready for our script.

The script below will display a notification with the title
“⏰ REMINDER” and the message “Have a break 🙂”.

The notification will appear for 5 seconds ( timeout=5 ) every 15 seconds ( time.sleep(15) ).

The notification will have as its icon the file “icon.ico” contained within the folder where we decide to save our script.

Please note: the “app_icon” parameter only accepts .ico type files



import time 
import pathlib 
from plyer import notification 

curr_path = pathlib.Path(__file__).resolve().parent 

notification_message= ''' 
Have a break 🙂 
''' 

if __name__ == "__main__" : 
    while ( True ): 

        notification.notify( 
            title= "⏰ REMINDER" , 
            message=notification_message, 
            timeout= 5 , 
            app_name= "My Notification" , 
            app_icon= str (curr_path)+ "\\icon.ico" , 
        ) 

        time.sleep( 15 )


Enter fullscreen mode Exit fullscreen mode

Here is the final result:

Desktop reminder


Follow me #techelopment

Medium: @techelopment
Dev.to: Techelopment
facebook: Techelopment
instagram: @techelopment
X: techelopment
telegram: @techelopment_channel
youtube: @techelopment
whatsapp: Techelopment

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay