34

Is it possible to add a notification in windows using python? Like a notification box with some information about an update or something

In windows if you didn't already figure that by this picture..

notification

3

4 Answers 4

52

First, install win10toast by using pip:

pip install win10toast

Then, import it:

from win10toast import ToastNotifier

Make a variable called toast:

toast = ToastNotifier()

Show the toast variable:

toast.show_toast(
    "Notification",
    "Notification body",
    duration = 20,
    icon_path = "icon.ico",
    threaded = True,
)

It should look something like this:

python toast notification

1
27

You can use Jason Chen's balloontip.py for this. It's almost 50 lines of code so I won't be pasting it here.

Seems to work in Windows 10 as well.

Thanks to zack for finding this gem.

1
18

There is also Windows-10-Toast-Notifications on Github.

It works on windows 10 (with pywin32) and it allows several notifications.

enter image description here

1
  • This seems to be exactly the win10toast package in user13096898's answer.
    – Niko Fohr
    Feb 12, 2021 at 16:09
11

You can use you plyer to display notifications:

from plyer import notification

notification.notify(
title = "Sample Notification",
message = "This is a sample notification",
timeout = 10
)

Or you can run this code and generate notifications:

from plyer import notification

import tkinter as tk

root = tk.Tk()

tk.Label(root , text = 'NOTIFICATION DEVELOPER').grid(row = 0, column = 0)
tk.Label(root , text = 'Notification Title:').grid(row = 3, column = 0)
tk.Label(root , text = 'Notification Message').grid(row = 4, column = 0)
tk.Label(root , text = 'Seconds for which it appears'). grid(row = 5, column = 0)

t1 = tk.Entry(root)
t1.grid(row = 3, column = 1)

m = tk.Entry(root)
m.grid(row = 4, column = 1)

tm = tk.Entry(root)
tm.grid(row = 5, column = 1)

def strt():
    a = int(tm.get())
    notification.notify(
    title = t1.get(),
    message = m.get(),
    timeout = a
    )
tk.Button(root , text = 'START NOTIFICATION' , command = strt).grid(row = 6, column = 0)

root.mainloop()

If you want he notifications to be displayed again after some time, you can use time.sleep(a) and loop the code. (a = time after which the notification will be displayed again.

For inserting icons, use app_icon:

app_icon = 'Full path of .ico file'
1
  • 1
    works without win32api
    – serv-inc
    Jun 21, 2022 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.