天天看點

Python 發送 WIN 10 通知消息

文章目錄

  • ​​Python 發送 WIN 10 通知消息​​
  • ​​1、安裝庫​​
  • ​​2、編寫代碼​​

Python 發送 WIN 10 通知消息

1、安裝庫

pip install win10toast      

2、編寫代碼

from win10toast import ToastNotifier
import _thread
from time import sleep

"""
win10toast 的庫底層為win32api、win32con和win32gui
"""

toaster = ToastNotifier()


def show_toast():
    toaster.show_toast("通知标題",
                       "通知内容",
                       icon_path=None,
                       duration=5,
                       threaded=True)


def send():
    _thread.start_new_thread(show_toast, ())
    sleep(0.1)


if __name__ == '__main__':
    send()