Home » Display toast notifications using Python

Display toast notifications using Python

by maxguy71

win10toast is an easy-to-use Python library for displaying Windows 10 Toast Notifications which is useful for Windows GUI development.

A toast is a small, informational window displayed by certain kinds of software, especially instant messaging clients such as AOL Instant Messenger, Windows Live Messenger, XFire and Trillian.

Toasts notify users of various kinds of events, such as reception of new e-mail, a change in a peer’s availability, or a change in network connectivity.

Toasts can comprise a short text message and can optionally include a small image and icon.

It is possible for the user to disable these in Windows 10 using the group policy editor

Installation

pip install win10toast

Requirements

Installation of pywin32

pypiwin32
setuptools

Code examples

In this example the text to display is “Python toast example”, it uses an icon called “python.ico” and the toast will appear for 5 seconds

from win10toast import ToastNotifier

toaster = ToastNotifier()

toaster.show_toast("Hello World",
                   "Python toast example",
                   icon_path="python.ico",
                   duration=5)

and another example

import time
from win10toast import ToastNotifier

toaster = ToastNotifier()

toaster.show_toast("Example two",
                   "Python toast example 2",
                   icon_path="python.ico",
                   duration=10,
                   threaded=True)
				   
# Wait for threaded notification to finish

while toaster.notification_active(): time.sleep(0.1)

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