Reputation: 20587
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..
Upvotes: 37
Views: 93645
Reputation: 111
It's recommended to use win11toast
because win10toast
has some issues (e.g. missing support to interactive toasts) and hasn't been updated for 7 years.
Although it is called
win11toast
, it actually works on Windows 10 as well.
First, install it with pip
python -m pip install win11toast
Let's create a simple toast
from win11toast import toast
toast('Hello Python🐍')
Or an interactive toast
from win11toast import toast
toast('Hello Python', 'Click to open url', on_click='https://www.python.org')
Upvotes: 1
Reputation:
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:
Upvotes: 54
Reputation: 131
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'
Upvotes: 13
Reputation: 1673
There is also Windows-10-Toast-Notifications on Github.
It works on windows 10 (with pywin32) and it allows several notifications.
Upvotes: 18
Reputation: 1470
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.
Upvotes: 27