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)) |
How do I get buttons to work?
Hi guys, I've created this as an easy to use package
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
Well, this attempt is purely C# ish, where you don't write all that XML structure in a string, just add elements (that probably in the background either way ends up in XML structure) and XML was stated in the first line of the function.
Managed to fix issue with XML too, had to remove all the spaces at the start of each line, add "", give all elements their "IDs" and attributes if needed, no images from outside the local disk even then you had to give full path, buttons don't exist, all other functions are kind of out, unless that's because used older version, since latest (at that time) was experiencing import issues.