How to push notification using Python?

 Pushing notification in python is very easy.

Image credit: conorjohanlon.com

Requirements:

You just need to install a module called plyer. To install it just paste the following command in your terminal.

pip install plyer

Importing modules:

As for now we just need notification function from plyer so we will just import notification from plyer.

from plyer import notification

Full Code:


from plyer import notification

notification.notify(
    title = "Notification title",
    message = "Notification message content",
    app_icon = None,#file path of image icon which you want to give to notification
    timeout = 10,# in seconds 1 = 1sec
)

Suggestion:

You can make a function for notification in your project, It will help you in calling this function again and again.

Like:


def notify(t,m):
    notification.notify(
    title = t,
    message = m,
    app_icon = None,
    timeout = 10,
)
Every time you want to call this function just pass following command
notify('Notification title','Notification message content')

If you have any query and suggestion please comment down below. Do check out our other helpful articles.

Post a Comment

0 Comments