python - 用 python 中的图像赢得 10 个 toast 通知

标签 python

有没有办法使用 python 在 Windows 10 中创建交互式 toast 通知? 目前我正在使用 plyer,有时我会使用 win10toast。 当有人点击它时,我希望它在网络浏览器中打开一个页面并包含图像、图标、文本和用户输入

最佳答案

对于图像部分,您可以使用模块 winrt像这样:

import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom

nManager = notifications.ToastNotificationManager
notifier = nManager.create_toast_notifier(r"C:\Users\Admin\AppData\Local\Programs\Python\Python38\python.exe")

tString = """
<toast>
    <visual>
        <binding template='ToastGeneric'>
            <text>Another Message from Tim!</text>
            <text>Hi there!</text>
            <image placement="appLogoOverride" hint-crop="circle" src="https://picsum.photos/48?image=883"/>
        </binding>
    </visual>
</toast>
"""

xDoc = dom.XmlDocument()
xDoc.load_xml(tString)

notification = notifications.ToastNotification(xDoc)

#display notification
notifier.show(notification)

此外,您可以在三个地方放置图像:AppLogoOverride , InlineHero .

关于python - 用 python 中的图像赢得 10 个 toast 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62826794/

相关文章:

python - 将 Pandas df 列转换为 JSON 字符串

python - 为什么 Python 不能在闭包中增加变量?

python - Python 中的 Web 服务?

python3 时间戳字符串中的纪元

从多个位置导入模块时的 python3 相对导入

python - 使用 Pythonanywhere 上传到 Google Drive

python - psycopg : Python. h:没有这样的文件或目录

Python - 每次修改整个字典时找到平均值的最快方法?

python - 如何从数据帧中获取数组或列表(其中 python 读取为 str 格式类型)?

python - 如何使用日志记录 Python 模块写入文件?