Skip to content

Instantly share code, notes, and snippets.

@MarcAlx
Last active January 24, 2023 22:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MarcAlx/443358d5e7167864679ffa1b7d51cd06 to your computer and use it in GitHub Desktop.
Save MarcAlx/443358d5e7167864679ffa1b7d51cd06 to your computer and use it in GitHub Desktop.
Send Windows notifications from python3
# -*- coding: utf-8 -*-
# Created by Marc_Alx
#
# pip install winrt
# Documentation here : https://github.com/Microsoft/xlang/tree/master/src/package/pywinrt/projection
# NB Only works with version of Windows that supports 'windows.ui.notifications'
#
# Requirements
# Windows 10, October 2018 Update or later.
# Python for Windows, version 3.7 or later
# pip, version 19 or later
#
import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom
#create notifier
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier();
#define your notification as string
tString = """
<toast>
<visual>
<binding template='ToastGeneric'>
<text>Sample toast</text>
<text>Sample content</text>
</binding>
</visual>
</toast>
"""
#convert notification to an XmlDocument
xDoc = dom.XmlDocument()
xDoc.load_xml(tString)
#display notification
notifier.show(notifications.ToastNotification(xDoc))
@krn17
Copy link

krn17 commented Jan 24, 2023

is there a way to stack upcoming notifications over the previous ones as they come?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment