網站首頁 編程語言 正文
前言
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()
補充
Win10 沒有提供簡單命令行方式來觸發桌面通知,所以只能使用Python來寫通知腳本。
一番搜索,找到?win10toast?。但這開源倉庫已無人維護,通過 github fork 的關系圖,找到?win10toast-click,一個正在更新功能更全的 Python 第三方模塊。
使用與場景
qBittorrent 支持下載完成后運行外部程序,由于 qBittorrent 沒有下載完成后桌面通知的功能,所以我們通過Python腳本來完成。
通過?win10toast-click
?倉庫中示例,就可以完成一個簡單的通知腳本。
import argparse from win10toast_click import ToastNotifier parser = argparse.ArgumentParser() parser.add_argument('--title', help='通知標題') parser.add_argument('--message', help='通知內容') args = parser.parse_args() toaster = ToastNotifier() toaster.show_toast(title=args.title, msg=args.message)
qBittorrent 提供了一些參數可以傳遞給調用程序,使用?argparse
?內建模塊來接收。
qBittorrent 運行外部程序
python <腳本路徑>/qb_win_toast.py --title "下載完成" --message "%N 下載完成"
原文鏈接:https://www.cnblogs.com/lwsbc/p/15851236.html
相關推薦
- 2022-12-12 C#中TextBox的橫線樣式及占位提示詳解_C#教程
- 2022-09-13 C#?wpf使用ListBox實現尺子控件的示例代碼_C#教程
- 2022-08-10 C語言如何在字符數組中插入一個字符_C 語言
- 2022-09-26 Pytorch模型訓練和模型驗證
- 2022-08-21 C語言實現隊列的示例詳解_C 語言
- 2022-11-23 Python利用keyboard模塊實現鍵盤記錄操作_python
- 2022-08-02 淺談Redis常見延遲問題定位與分析_Redis
- 2022-03-26 R語言繪制尺子的實現示例_R語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支