Last active
December 11, 2024 15:24
-
-
Save MarcAlx/443358d5e7167864679ffa1b7d51cd06 to your computer and use it in GitHub Desktop.
Send Windows notifications from python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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)) |
Hi guys, I've created this as an easy to use package
Wow nice work! happy to have helped you with this gist.
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
Hi guys, I've created this as an easy to use package
https://pypi.org/project/win11toast/