继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

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

OverWrite_235
关注TA
已关注
手记 138
粉丝 10
获赞 67

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

file

安装调起通知的依赖库

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()
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP