<p>您可以使用这个名为<a href="https://pypi.org/project/winrt/" rel="nofollow noreferrer">winrt</a>的python模块</p>
<pre><code>#importing required modules
import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom
from time import sleep
# create notification objects
nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(r"C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\python.exe")
# PUT YOUR USERNAME INSTEAD OF USERNAME
# put your python path there.
# define the xml notification document.
tString = """
<toast>
<visual>
<binding template='ToastGeneric'>
<text>Another Message from Tim!</text>
<text>Hi there!</text>
</binding>
</visual>
<actions>
<action
content="View Message"
arguments="test1"
activationType="backround"/>
</actions>
</toast>
"""
# load the xml document.
xDoc = dom.XmlDocument()
xDoc.load_xml(tString)
notification = notifications.ToastNotification(xDoc)
# display notification
notifier.show(notification)
# this is not called on the main thread.
def handle_activated(sender, _):
print([sender, _])
print('Button was pressed!')
# add the activation token.
activated_token = notification.add_activated(handle_activated)
# do something else on the main thread.
while True:
sleep(1)
</code></pre>
<p>我从中了解到:这个<a href="https://github.com/microsoft/xlang/issues/741" rel="nofollow noreferrer">issue</a></p>