首页 > 解决方案 > 当我尝试使用 winrt 发出通知时,没有显示通知

问题描述

我正在尝试让 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("app-id");


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))

但是,当我运行它时,没有任何通知出现。

我的系统符合winrt的要求

Windows 10, October 2018 Update or later.
Python for Windows, version 3.7 or later
pip, version 19 or later

如何让通知显示?我不能使用其他模块,因为 winrt 是唯一一个(据我所知),您可以在其中创建按钮等通知上的 ui 元素。我认为 Windows 不会阻止它显示,因为其他不符合我要求的模块会显示通知。

标签: pythonwindowsnotificationswindows-runtime

解决方案


推荐阅读