我正在尝试让 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 元素,例如按钮。
我刚刚解决了同样的问题,消除了错误,但通知没有显示。
This 微软文档 https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh802768(v=vs.85)建议“重要提示:每次调用 CreateToastNotifier 时,您都必须在“开始”屏幕上包含应用程序快捷方式的 AppUserModelID。如果您不这样做,您的 Toast 将不会显示。”
然后我按照我找到的说明进行操作here https://jcutrer.com/windows/find-aumid找到 AppUserModelID,它是我的 Python 可执行文件的完整路径。
例如:
notifier = nManager.create_toast_notifier("C:\\...\\Programs\\Python\\Python38\\python.exe")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)