首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >显示windows 10通知- Python

显示windows 10通知- Python
EN

Stack Overflow用户
提问于 2021-04-21 01:47:08
回答 2查看 122关注 0票数 0

简而言之:如何让windows10通知只有一个按钮,或者只是让通知可点击?(使用python)

Long:我希望在windows10中进行通知,并且希望在弹出通知时能够点击通知。当随后单击通知时,它应该执行一个函数。我看了很多解决方案,但它们似乎都不管用,到目前为止,我得到的最好的解决方案是“Windows10吐司通知”(win10toast),但Charnelx对其进行了修改。为了安装他的代码,我尝试使用以下代码:

代码语言:javascript
复制
pip install git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast

但是,当我尝试安装它时,它似乎无法工作。我使用的是python 3.8.9。

我希望有人能帮助我。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-08-04 06:07:08

您可以使用这个名为winrt的python模块。

代码语言:javascript
复制
#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

票数 2
EN

Stack Overflow用户

发布于 2021-04-28 22:40:44

在网上转了一段时间后,我偶然发现了这个资源。它提供了单击通知的选项。

Link for resources

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67183880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档