python实现Windows通知

133 阅读1分钟

image.png

运行代码前请先安装win10toast库

命令pip install win10toast

可使用pyinstaller库打包成exe

安装pyinstaller

命令pip install pyinstaller

使用pyinstaller打包exe

命令pyinstaller your_script_name.py

import time
from win10toast import ToastNotifier

toaster = ToastNotifier()

while True:
    current_time = time.strftime("%H:%M")

    if current_time == "09:00":
        toaster.show_toast(
            "开始工作咯",
            "再不工作工资扣光咯。",
            icon_path="上班.ico",
            duration=5
        )
        print(f"{current_time}: 上班提醒 - 现在是上午上班时间。")
    elif current_time == "12:00":
        toaster.show_toast(
            "下班下班",
            "又到了一天中干饭最积极的时刻了。",
            icon_path="下班.ico",
            duration=5
        )
        print(f"{current_time}: 下班提醒 - 现在是上午下班时间了。")
    elif current_time == "13:00":
        toaster.show_toast(
            "开始工作咯",
            "再不工作工资扣光咯。",
            icon_path="上班.ico",
            duration=5
        )
        print(f"{current_time}: 上班提醒 - 现在是下午上班时间了。")
    elif current_time == "18:00":
        toaster.show_toast(
            "下班下班",
            "下班下班Let's go",
            icon_path="下班.ico",
            duration=5
        )
        print(f"{current_time}: 下班提醒 - 现在是下午下班时间了。")

    time.sleep(60)