简而言之:如何让windows10通知只有一个按钮,或者只是让通知可点击?(使用python)
Long:我希望在windows10中进行通知,并且希望在弹出通知时能够点击通知。当随后单击通知时,它应该执行一个函数。我看了很多解决方案,但它们似乎都不管用,到目前为止,我得到的最好的解决方案是“Windows10吐司通知”(win10toast),但Charnelx对其进行了修改。为了安装他的代码,我尝试使用以下代码:
pip install git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast但是,当我尝试安装它时,它似乎无法工作。我使用的是python 3.8.9。
我希望有人能帮助我。
发布于 2021-08-04 06:07:08
您可以使用这个名为winrt的python模块。
#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)我在哪里了解到这一点:这个issue。
发布于 2021-04-28 22:40:44
在网上转了一段时间后,我偶然发现了这个资源。它提供了单击通知的选项。
https://stackoverflow.com/questions/67183880
复制相似问题