win10toast
调用win10toast即可触发Windows10通知,该库底层为win32api、win32con和win32gui
安装
pip install win10toast
初试
import time
from win10toast import ToastNotifier
toaster = ToastNotifier()
toaster.show_toast("Hello World!!!",
"Python is 10 seconds awsm!",
icon_path="python.ico",
duration=10)
toaster.show_toast("Example two",
"This notification is in it's own thread!",
icon_path=None,
duration=5,
threaded=True)
# 等待线程通知完成
while toaster.notification_active():
time.sleep(0.1)
效果

方法介绍
win10toast是一个用于Windows 10操作系统的Python模块,用于创建和显示Windows 10通知。以下是win10toast模块的所有方法可以用于创建、显示和管理Windows 10通知。:
- ToastNotifier(): 创建一个ToastNotifier对象,用于发送通知。
- show_toast(title, msg=None, duration=5, icon_path=None): 显示通知,其中title是通知的标题,msg是通知的正文,duration是通知持续时间(以秒为单位),icon_path是通知图标的路径。
- hide_toast(): 隐藏当前正在显示的通知。
- update_title(title): 更新当前正在显示的通知的标题。
- update_message(msg): 更新当前正在显示的通知的正文。
- update_duration(duration): 更新当前正在显示的通知的持续时间。
- update_icon(icon_path): 更新当前正在显示的通知的图标。
- exists(): 检查当前是否有正在显示的通知。
- get_notification_duration(): 获取当前正在显示的通知的持续时间。
- get_notification_title(): 获取当前正在显示的通知的标题。
- get_notification_message(): 获取当前正在显示的通知的正文。
- get_notification_icon(): 获取当前正在显示的通知的图标。
ToastNotifier通知设置
win10toast.ToastNotifier
def show_toast(self,
title: str = "Notification",
msg: str = "Here comes the message",
icon_path: Any = None,
duration: int = 5,
threaded: bool = False) -> bool
title=“Notification”:str。通知标题。msg=“Here comes the message”:str。通知内容。icon_path=None:str or None。通知图标路径, 必须是.ico文件。duration=5:int。唤起通知后持续多久再销毁通知,单位为秒。threaded=False:bool。是否将该通知加入一个新线程。如果为True,该通知将加入一个新线程,程序继续往后执行,不等通知销毁。
相关属性
.wc
.hwnd
.hinst
.classAtom
notification_active
判断是否有通知处于活动状态未销毁。
# 导入
from win10toast import ToastNotifier
# 创建通知对象
TN = ToastNotifier()
# 唤起通知,并加入线程,程序继续向下执行,不等待通知销毁
TN.show_toast("通知", "这里通知一条消息", "./n8.ico", 10, threaded=True)
# 输出通知状态
print(TN.notification_active()) ---> True
------
# 导入
from win10toast import ToastNotifier
# 创建通知对象
TN = ToastNotifier()
# 唤起通知,不加入线程,程序等待通知销毁后再继续执行
TN.show_toast("通知", "这里通知一条消息", "./n8.ico", 10, threaded=False)
# 输出通知状态
print(TN.notification_active()) ---> False
on_destroy
.on_destroy(hwnd, msg, wparam, lparam)
销毁一个处于活跃状态的通知,一般是在其线程中活跃的通知。只需传入hwnd = TN.hwnd即可,其他参数传入None。
本文介绍了Python的win10toast模块,用于在Windows 10上创建和显示通知。内容包括安装、基本用法、方法介绍,如ToastNotifier对象、show_toast()、hide_toast()等,并提供了通知的相关属性和设置说明。
492

被折叠的 条评论
为什么被折叠?



