我正在嘗試讓 winRT 發(fā)送通知。我嘗試這樣做來發(fā)出通知: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))然而,當(dāng)我嘗試運(yùn)行它時(shí),它返回此錯(cuò)誤。 notifier = notifications.ToastNotificationManager.create_toast_notifier()RuntimeError: Element not found.我的系統(tǒng)滿足winrt的要求Windows 10, October 2018 Update or later.Python for Windows, version 3.7 or laterpip, version 19 or later我該如何修復(fù)這個(gè)錯(cuò)誤?我無法使用其他模塊,因?yàn)?winrt 是唯一一個(gè)(據(jù)我所知),您可以在通知上創(chuàng)建 ui 元素,例如按鈕。
3 回答

慕蓋茨4494581
這個(gè)方法對我有用
TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊
這個(gè)方法對我有用Python 3.9.1
并且pip 21.0.1
打開 PowerShell輸入以下命令,get-StartApps
它會(huì)返回Name
和AppID
Name????????????AppID?????????????????????????????????????????? ----????????????----- Calculator??????Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
這可以很方便
get-StartApps | Where-Object {$_.Name -like '*Application Name*'}
get-StartApps | Where-Object {$_.Name -like '*Python*'}
復(fù)制/AppID
粘貼到create_toast_notifier("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App")
例子:
#create?notifiernManager?=?notifications.ToastNotificationManager notifier?=?nManager.create_toast_notifier("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");

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

慕碼人2483693
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊
發(fā)生異常是因?yàn)槟枰峁┮粋€(gè)applicationID
像create_toast_notifier()
這樣的例子create_toast_notifier("MyApplicationId")
。
添加回答
舉報(bào)
0/150
提交
取消