windows10定时调起系统通知,每一个小时提醒该喝水了...(win10定时提醒休息)

网友投稿 503 2022-07-28

win10toast是一个windows通知的出发框架,使用它可以轻松的调起系统通知。通过它可以很方便的做一个定时通知的功能应用。

安装调起通知的依赖库

pip install win10toast

导入相关的第三方依赖库

from win10toast import ToastNotifier # 导入系统通知对象

import time # 系统时间模块

import datetime

from threading import Timer # 定时器

初始化通知调用对象

notify = ToastNotifier() # 初始化系统通知对象

初始化windows通知相关的参数,设置定时通知间隔时间等。

notify_head = '主人,来通知啦!'

notify_min = 1.0

notify_text = '已经过了' + str(int(notify_min)) + '分钟了,该喝水了!'

notify_sen = notify_min * 1

通知调起时,是使用win10toast的show_toast()函数,参数和定义如下面。

'''

def show_toast(self, title="Notification", msg="Here comes the message",

icon_path=None, duration=5, threaded=False):

"""Notification settings.

:title: notification title

:msg: notification message

:icon_path: path to the .ico file to custom notification

:duration: delay in seconds before notification self-destruction

"""

'''

show_toast()函数的使用,采用timer定时器来定时的调起应用发送通知。

def show_toast():

print('当前时间:%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

notify.show_toast(f"{notify_head}", f"{notify_text}", duration=5, threaded=True, icon_path='水杯.ico')

while notify.notification_active():

time.sleep(0.005)

timer = Timer(notify_sen, show_toast)

timer.start()

主函数入口调用。

if __name__ == '__main__':

show_toast()

【往期精彩】

百度图片下载器2.0

gif动态图片生成器,多张图片组合后生成动图...

python几个常见的数据处理操作,一行代码就能完成!

过年了,用 PyQt5 生成一副春联吧...

记录一下python中的十大%占位符对应的格式化...

出处:https://cnblogs.com/lwsbc/p/15851236.html

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:百度图片下载器2.0(百度图片手机怎么下载)
下一篇:如何在控制台实现一个数据管理系统(包括MYSQL数据库的增删改查)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~