关于python:windows10定时调起系统通知每一个小时提醒该喝水了

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()

我是 [Python 集中营]、很快乐您看到了最初, 我是一个专一于 Python 常识分享的公众号,心愿能够失去您的关注~

【往期精彩】

百度图片下载器2.0

gif动静图片生成器,多张图片组合后生成动图…

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

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

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

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理