Sunday, June 1, 2025
  • About
  • Advertise
  • Careers
  • Contact
Connect 4 Programming
  • Home
  • Python
  • Java
  • SQL
  • JavaScript
  • HTML
  • Data Structure
  • GIT
  • OOP
  • Interview Questions
  • Login
No Result
View All Result
Connect 4 Prog
Home Python

Desktop Notifier in Python

Desktop Notifier in Python

This article explains how to create a simple desktop notifier application using Python.

A desktop notifier is a straightforward application that generates notification messages in the form of pop-up alerts on the desktop.

Related posts

Tkinter GUI Projects With Python

Tkinter GUI Projects with Python PDF Guide

March 28, 2025
Python String split()

Python String split()

October 30, 2024

Notification content

In the example we use in this article, the content that will appear as notification on desktop is the top news headlines of the day.

To fetch the top headlines, we will use a Python script to scrape news headlines.

image 6
image 7
image 8

It is a simple Python script that parses the news headlines available in XML format.

Note: To understand how XML parsing works, please refer to this article: XML parsing in Python

A sample news item generated by the above Python script looks like this:

{'description': 'Months after it was first reported, the feud between Dwayne Johnson and 
                 Vin Diesel continues to rage on, with a new report saying that the two are 
                 being kept apart during the promotions of The Fate of the Furious.',
 'link': 'http://www.hindustantimes.com/hollywood/vin-diesel-dwayne-johnson-feud-rages-
on-they-re-being-kept-apart-for-fast-8-tour/story-Bwl2Nx8gja9T15aMvcrcvL.html',
 'media': 'http://www.hindustantimes.com/rf/image_size_630x354/HT/p2/2017/04/01/Pictures
/_fbcbdc10-1697-11e7-9d7a-cd3db232b835.jpg',
 'pubDate': b'Sat, 01 Apr 2017 05:22:51 GMT ',
 'title': "Vin Diesel, Dwayne Johnson feud rages on; they're being deliberately kept apart"}

Save this Python script as topnews.py (as we import it by this name in our desktop notifier app).

Installations

Now, to create a desktop notifier, you need to install a third-party Python module, notify2.

You can install notify2 using a simple pip command:

pip install notify2

Desktop notifier app

Now, we write the Python script for our desktop notifier.

Consider the code below:

image 11

Let us try to analyze above code step by step:

  • Before we can send any notifications, we need to initialize a D-Bus connection. D-Bus is a message bus system, a simple way for applications to talk to one another. So, D-Bus connection for notify2 in current Python script is initialized using:
notify2.init("News Notifier")

Here, the only argument we passed is the app name. You can set any arbitrary app name.

  • Now, we create a notification object, n using:
n = notify2.Notification(None, icon = ICON_PATH)

The general syntax for above method is:

notify2.Notification(summary, message='', icon='')

Here,

  • summary: The title textmessage: The body texticon: Path to an icon image

Currently, we have set summary as None and passed the ICON_PATH as icon argument.Note: You need to pass complete path of the icon image.

  • You can optionally set the urgency level of notifications using set_urgency method:
n.set_urgency(notify2.URGENCY_NORMAL)

The available constants are:

  • notify2.URGENCY_LOW
  • notify2.URGENCY_NORMAL
  • notify2.URGENCY_CRITICAL
  • Another optional utility is set_timeout method using which, you can explicitly set the display duration in milliseconds as shown below:
n.set_timeout(10000)
  • Now, as we iterate through each news item one by one, we need to update the notification object with a new summary and message using update method:

n.update(newsitem['title'], newsitem['description'])

  • In order to display a notification, simply call show() method of the Notification object like this:

n.show()

A sample screen shot of the desktop when you run the above Python script:

image 13

Github repository for this desktop notifier application: Desktop-Notifier-Example

Related Posts

71 Python Projects with References and Source Code
Python

71 Python Projects with References and Source Code

March 28, 2025
OOPS in Python Handwritten Notes
Python

OOPS in Python Handwritten Notes

March 28, 2025
Python Programming and SQL PDF
Python

Python Programming and SQL PDF

March 28, 2025
Basic Python Programs
Python

Basic Python Programs Handwritten PDF

March 28, 2025
Python Programming for Beginners PDF: Your Step-by-Step Guide to Learning Python
Python

Python Programming for Beginners PDF: Your Step-by-Step Guide to Learning Python

March 28, 2025
Python Notes Handwritten
Python

Python Notes Handwritten PDF

March 28, 2025

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

POPULAR NEWS

  • 71 Python Projects with References and Source Code

    71 Python Projects with References and Source Code

    0 shares
    Share 0 Tweet 0
  • OOPS in Python Handwritten Notes

    4 shares
    Share 0 Tweet 0
  • Most Asked JavaScript Interview (100 Q&A) PDF

    0 shares
    Share 0 Tweet 0
  • Most Asked Java Interview (100 Q&A) PDF

    0 shares
    Share 0 Tweet 0
  • Top 50 Java Interview Questions and Answers PDF

    0 shares
    Share 0 Tweet 0
Connect 4 Programming

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc.

Follow us on social media:

Recent News

  • Tkinter GUI Projects with Python PDF Guide
  • Python String split()
  • Desktop Notifier in Python

Category

  • Data Structure
  • GIT
  • HTML
  • Interview Questions
  • Java
  • JavaScript
  • OOP
  • Programming
  • Python
  • SQL

Recent News

Tkinter GUI Projects With Python

Tkinter GUI Projects with Python PDF Guide

March 28, 2025
Python String split()

Python String split()

October 30, 2024
  • About
  • Advertise
  • Careers
  • Contact

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Python
  • Java
  • SQL
  • JavaScript
  • HTML
  • Data Structure
  • GIT
  • OOP
  • Interview Questions