【发布时间】:2020-10-06 18:16:16
【问题描述】:
我正在尝试让 winRT 发送通知。 我尝试这样做是为了发出通知:
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))
但是,当我尝试运行它时,它会返回此错误。
notifier = notifications.ToastNotificationManager.create_toast_notifier()
RuntimeError: Element not found.
我的系统满足winrt的要求
Windows 10, October 2018 Update or later.
Python for Windows, version 3.7 or later
pip, version 19 or later
我该如何解决这个错误?我不能使用其他模块,因为 winrt 是唯一一个(据我所知),您可以在其中创建按钮等通知上的 ui 元素。
【问题讨论】:
标签: python windows notifications windows-runtime