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中的十大%占位符對應的格式化...