Reputation: 41
I'm looking for a solution to create notifications in Python for Windows 10. I also want to be able to click on the notification and generate an action. If the notification is not clicked, I want it to stay in the windows action center in order to be able to use it later.
For this purpose, the best I found is the library win10toast_click. It works well, except for one thing: if the notification is not clicked, it doesn't stay in the windows action center. It literally disappears.
It's pretty strange, since the previous version of this library, win10toast_persist has this functionality.
Has anyone encountered this kind of issue? Or any clues to solve it. Maybe another solution exists that can answer my requirements?
For your information, this is the test code I use:
import win10toast_click
def test():
print("Hello")
toaster = win10toast_click.ToastNotifier()
toaster.show_toast(
"Example one",
"Click to hello"
icon_path=None
duration=None
threaded=True
callback_on_click=test
)
Upvotes: 1
Views: 548
Reputation: 366
You can use winrt like this:
import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom
import sys
# get python path
path = sys.executable
#create notifier
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(path)
#define your notification as
tString = """
<toast>
<visual>
<binding template='ToastGeneric'>
<text>New notifications</text>
<text>Text</text>
<text>Second text</text>
</binding>
</visual>
</toast>
"""
#convert notification to an XmlDocument
xDoc = dom.XmlDocument()
xDoc.load_xml(tString)
#display notification
notifier.show(notifications.ToastNotification(xDoc))
Upvotes: 0