adsterra

Create desktop Notifier using Python |Window 10 Toast|win10toast module



Python Desktop Notifier

Python Desktop Notifier using  Win10toast module

                  In this article ,I am going to show you how to create a simple Desktop Notifier application using Python. A desktop notifier is a simple application which generate a notification message in form of a pop-up message on desktop. We will be using window 10 Toast module for the same.

What is Windows 10 Toast Notifications?
            It is an easy-to-use Python built in library for displaying Windows 10 Toast Notifications which is useful for display any notification on your desktop. It is also useful for Windows GUI development.

Module Needed

1.time: This module works with the time object and is installed by default
2.win10toast: win10toast module is used to access the features of the hardware. This module comes built-in with Python. We need to install it by pip command. To install this module type the below command in the terminal.

Syntax:-
Show_toast() function contains the following parameters.
show_toast(title=’Notification’, message=’Here comes the message’, icon_path=None, duration=5, threaded=False)

Parameters:
title: It contains title of the notification.
message: It contains actual notification message.
icon_path: It contains the path to .ico file.
duration: It define the notification destruction active duration.
The package is available in Pypi and  can be easily installed with pip.

Python –m pip install win10toast
Once the installation has been completed you could try a simple notification.

Let’s try with implementation.
            First import the win10toast library and create the object of ToastNotifier.Then using showtoast() we create a notification that contains a title,message that given by notification,and duration of that notification.



Here’s the code number 1:-

from win10toast import ToastNotifier
#one time initialization
#creating the object of ToastNotifier
obj = ToastNotifier()
#show notification whenever needed
obj.show_toast("Programming Soup!","Alert!Here comes the message Yes", icon_path=None,duration=10)# 10 seconds

See the output of this code:-
Notification Output code 1



Code number 2:

import time
from win10toast import ToastNotifier
#one time initialization
#creating the object of ToastNotifier
obj = ToastNotifier()
#show notification whenever needed
obj.show_toast("Programming Soup!","You Got the Notification",        icon_path=None,duration=10,threaded=True)# 10 seconds
#to check if any notifications are active ,use toaster.notification_active()
while toaster.notification_active():
    time.sleep(0.1)

Here is the output of second code:Notification output code 2


Guys! If You Got any type error in code or module installing error feel free to contact me

Post a Comment

0 Comments