Pythonでデスクトップにポップアップを通知する方法を解説します。二種類紹介しますので好きな方をご選択ください。
Plyerを使う場合
まずはPlyerを使う場合を紹介します。
GitHub - kivy/plyer: Plyer is a platform-independent Python wrapper for platform-dependent APIs
Plyer is a platform-independent Python wrapper for platform-dependent APIs - kivy/plyer
インストール方法
下記でインストール可能です。
pip install plyer
ポップアップ通知の表示方法
下記で実装できます。
from plyer import notification
notification.notify(
title="タイトル",
message="メッセージ",
timeout=10
)
一行目でライブラリをインポートします。
そして、notification.notify
で通知を実行します。title
にはタイトル、message
にはメッセージ、timeout
にはポップアップ通知が消えるまでの時間を設定できます。
下記が実行結果です。

win10toastを使う場合
続いてwin10toastを使う場合を紹介します。
GitHub - jithurjacob/Windows-10-Toast-Notifications: Python library to display Windows 10 Toast Notifications
Python library to display Windows 10 Toast Notifications - jithurjacob/Windows-10-Toast-Notifications
インストール方法
下記でインストール可能です。
pip install win10toast
ポップアップ通知の表示方法
下記で実装できます。
from win10toast import ToastNotifier
toaster = ToastNotifier()
toaster.show_toast("タイトル",
"メッセージ",
duration=10)
一行目でライブラリをインポートします。
そして、toaster = ToastNotifier()
でインスタンス化したのちにtoaster.show_toast
で通知を実行します。第一引数
にはタイトル、第二引数
にはメッセージ、duration
にはポップアップ通知が消えるまでの時間を設定できます。
下記が実行結果です。

Plyerとwin10toastの比較
PlyerはAndroid、iOS、Windows、OS X、Linuxなど様々なプラットフォームで使用できます。ただし、プラットフォームごとに使用できる機能に違いがあります。
win10toastは名前の通りWindowsしか使用できないようです。

様々なプラットフォームで使えるし、Github上での評価も高いので個人的にはPlyerの使用をお勧めします!
↓Pythonを始めるならこちらの本がオススメ
