我正在嘗試讓 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
它會返回Name
和AppID
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");

慕斯王
TA貢獻1864條經驗 獲得超2個贊
我剛剛解決了同樣的問題,消除了錯誤,但通知沒有顯示。
例如:
notifier?=?nManager.create_toast_notifier("C:\\...\\Programs\\Python\\Python38\\python.exe")

慕碼人2483693
TA貢獻1860條經驗 獲得超9個贊
發生異常是因為您需要提供一個applicationID
像create_toast_notifier()
這樣的例子create_toast_notifier("MyApplicationId")
。
添加回答
舉報
0/150
提交
取消