2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pythonでwindowsトースト通知

Last updated at Posted at 2025-06-08
  • 内容

pythonでデスクトップ通知を送る方法

  • 環境

    • os
      • win11
    • python
      • miniconda 23.5.2, python 3.11.13, pip 25.1
    • ライブラリ
      • plyer 2.1.0
      • win11toast 0.35
  • 通知種類

  • トースト通知

    • os標準の通知
    • トーストマシンみたいに飛び出してくるやつ
  • コード

plyer

from plyer import notification

notification.notify(    
title="タイトル",    
message="メッセージ",    
timeout=10
)

win11toast

from win11toast import toast
import time

toast('Hello')
  • 結果

image(13).png

  • win11toastの機能

公式ドキュメント

ボタンの追加と返り値の取得ができる

# コールバック関数:ボタンが押された時に呼ばれる
def on_button_click(args):    
print("✅ ボタンが押されました:", args)

# ボタン付きトースト通知を表示
toast(    
title="確認してください",    
body="今なにをしたいですか?",    
buttons=["食事する", "あとで", "無視する"],    
on_click=on_button_click
)

結果

image(14).png

「食事する」を押すと、

image(15).png

  • 他の機能

    • テキストボックスでの入力
    • 音の再生
    • 画像表示
    • etc
  • 課題

  • トースト通知だとゲーム中に気付かない

    • 別のオーバーレイなど試したい
      • PyQt5を触ったがゲーム中は見えなかった
  • 定期実行と組み合わせたい

    • 19:00に夕食の通知
      • 特定条件で再通知し続ける
        • 「食事する」ボタンを押すまで
        • パソコンを触り続けたら
        • など
    • 長時間パソコンを続けない, 適度な休憩・スタンディングに変えるなど知らせられるとうれしいかも?
  • まとめ

定期実行, カレンダー連携などと組み合わせて理想の通知プログラムを作ろう!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?