【问题标题】:Python toast notifications not propagating to Action CenterPython toast 通知未传播到操作中心
【发布时间】:2018-04-21 14:32:17
【问题描述】:
【问题讨论】:
标签:
python
python-3.x
notifications
windows-10
toast
【解决方案1】:
你可以使用这个名为winrt的python模块。
#importing required modules
import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom
from time import sleep
# create notification objects
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(r"C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\python.exe")
# PUT YOUR USERNAME INSTEAD OF USERNAME
# put your python path there.
# define the xml notification document.
tString = """
<toast>
<visual>
<binding template='ToastGeneric'>
<text>Another Message from Tim!</text>
<text>Hi there!</text>
</binding>
</visual>
</toast>
"""
# load the xml document.
xDoc = dom.XmlDocument()
xDoc.load_xml(tString)
notification = notifications.ToastNotification(xDoc)
# display notification
notifier.show(notification)