Home » Create a Desktop Notification with Python

Create a Desktop Notification with Python

Oracle Java Certification
Java SE 11 Programmer I [1Z0-815] Practice Tests
1 Year Subscription
Java SE 11 Programmer II [1Z0-816] Practice Tests
Java SE 11 Developer (Upgrade) [1Z0-817]
Spring Framework Basics Video Course

In this article we are going to show you how to create a desktop notification app to get a reminder to rest after every hour. Your message and alert can be absolutely anything you want.

For this task, you need to install a Python library known as Plyer, which is used to access the hardware components of your system. It is cross-platform so will work on Android, Windows, Linux, OS X and iOS

About

Plyer is a platform-independent api that uses features commonly found on various platforms, notably mobile ones, in Python.

You can refer to the following table to see what I supported on your platform, keep in mind that some of the features may not be available on a certain platform

Supported APIs

Platform Android iOS Windows OS X Linux
Accelerometer
Audio recording
Barometer
Battery
Bluetooth
Brightness
Call
Camera (taking picture)
Compass
CPU count
Devicename
Email (open mail client)
Flash
GPS
Gravity
Gyroscope
Humidity
IR Blaster
Keystore
Light
Native file chooser
Notifications
Orientation
Proximity
Screenshot
SMS (send messages)
Spatial Orientation
Speech to text
Storage Path
Temperature
Text to speech
Unique ID
Vibrator
Wifi

Install

pip install plyer

 

Syntax

notify(title=”, message=”, app_name=”, app_icon=”, timeout=10, ticker=”, toast=False)

Parameters:

title (str) – Title of the notification
message (str) – Message of the notification
app_name (str) – Name of the app launching this notification
app_icon (str) – Icon to be displayed along with the message
timeout (int) – time to display the message for, defaults to 10
ticker (str) – text to display on the status bar as the notification arrives
toast (bool) – simple Android message instead of a full notification

Example

import time
from plyer import notification
 
 
if __name__=="__main__":
 
        notification.notify(
            title = "YOUR HEADING HERE",
            message="A DESCRIPTION HERE" ,
           
            # displaying time
            timeout=5
)
        # waiting time
        time.sleep(10)

 

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More