为了账号安全,请及时绑定邮箱和手机立即绑定

当我尝试使用 winrt 发出通知时,出现错误

当我尝试使用 winrt 发出通知时,出现错误

胡说叔叔 2023-10-11 16:04:54
我正在尝试让 winRT 发送通知。我尝试这样做来发出通知:import winrt.windows.ui.notifications as notificationsimport winrt.windows.data.xml.dom as dom#create notifiernManager = notifications.ToastNotificationManagernotifier = nManager.create_toast_notifier();#define your notification as stringtString = """<toast>    <visual>        <binding template='ToastGeneric'>            <text>Sample toast</text>            <text>Sample content</text>        </binding>    </visual></toast>"""#convert notification to an XmlDocumentxDoc = dom.XmlDocument()xDoc.load_xml(tString)#display notificationnotifier.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 laterpip, version 19 or later我该如何修复这个错误?我无法使用其他模块,因为 winrt 是唯一一个(据我所知),您可以在通知上创建 ui 元素,例如按钮。
查看完整描述

3 回答

?
慕盖茨4494581

TA贡献1850条经验 获得超11个赞

这个方法对我有用Python 3.9.1并且pip 21.0.1


打开 PowerShell输入以下命令,get-StartApps它会返回NameAppID


Name            AppID                                          
----            -----
Calculator      Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
  • 这可以很方便

    • get-StartApps | Where-Object {$_.Name -like '*Application Name*'}

    • get-StartApps | Where-Object {$_.Name -like '*Python*'}

复制/AppID粘贴到create_toast_notifier("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App")

例子:

#create notifiernManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");



查看完整回答
反对 回复 2023-10-11
?
慕斯王

TA贡献1864条经验 获得超2个赞

我刚刚解决了同样的问题,消除了错误,但通知没有显示。

例如:

notifier = nManager.create_toast_notifier("C:\\...\\Programs\\Python\\Python38\\python.exe")
查看完整回答
反对 回复 2023-10-11
?
慕码人2483693

TA贡献1860条经验 获得超9个赞

发生异常是因为您需要提供一个applicationIDcreate_toast_notifier()
这样的例子create_toast_notifier("MyApplicationId")


查看完整回答
反对 回复 2023-10-11
  • 3 回答
  • 0 关注
  • 64 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信