使用Python在Windows 10上显示通知信息

此功能的实现主要使用 python 第三方库 win10toast

https://github.com/jithurjacob/Windows-10-Toast-Notifications

安装**win10toast**

pip install win10toast 

使用示例

from win10toast import ToastNotifier
toast = ToastNotifier()
toast.show_toast(title="This is a title", msg="This is a message",
                 icon_path=r"C:\Program Files\Internet Explorer\images\bing.ico", duration=10)

效果展示

img

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在 Windows 10 Toast 通知中添加一个监听按钮被点击的事件,可以使用 Python winrt 库和 XML 构建器创建一个包含自定义按钮的通知。下面是一个简单的示例代码: ```python import winrt.windows.ui.notifications as notifications import winrt.windows.data.xml.dom as dom # 创建 ToastNotificationManager 对象 toaster = notifications.ToastNotificationManager # 创建 ToastNotification 对象 toast = toaster.get_template_content(notifications.ToastTemplateType.ToastText02) # 获取 Toast 的 XML 节点 xml = dom.XmlDocument() xml.load_xml(toast.get_xml().get_xml()) # 添加一个按钮 actions = xml.getElementsByTagName("actions")[0] action = xml.createElement("action") action.setAttribute("content", "点击这里") action.setAttribute("arguments", "buttonClicked") action.setAttribute("activationType", "background") actions.appendChild(action) # 创建 ToastNotification 对象并显示 toast.add_node(xml) notifier = notifications.ToastNotificationManager.create_toast_notifier() notifier.show(toast) ``` 在上面的代码中,我们使用 `ToastNotificationManager` 对象创建了一个基本的 Toast 通知模板。然后,我们使用 `XmlDocument` 对象加载了该模板的 XML,以便能够修改它。我们通过 `getElementsByTagName` 方法获取到了 `actions` 节点,然后创建了一个新的 `action` 节点来表示监听按钮被点击的事件。我们设置了按钮的 `content`、`arguments` 和 `activationType` 属性。最后,我们将修改后的 XML 内容添加回 `ToastNotification` 对象中,并使用 `ToastNotificationManager` 创建了一个 `ToastNotifier` 对象并显示通知
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虚坏叔叔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值