8
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?

お昼休みですよ!決まった時間に自動で通知&チャイムが鳴るバックグラウンド風アプリ作成してみた!

Last updated at Posted at 2025-06-17

テレワークだと気づきません!

テレワークのとき、昼休憩の時間や終業時間に気づきますか?
社内にいるとチャイムが鳴るので気づきますが、テレワークだと気づかず仕事を続けてしまうことがあります。

今回はWindows起動時に自動実行されて、設定した時刻になると、画像のように通知されてチャイムが鳴るバックグラウンド風アプリを作成しました!

image.png

また、チャイム音はリンク先にある「学校のチャイム」にしました。

実装

コード

ALARM_TIMESにアラーム時刻、SOUND_PATHに好きな音声ファイルの絶対パスを設定すれば使用できます。

time_announcement.py
import tkinter as tk
import threading
import time
import datetime
import pygame

ALARM_TIMES = ["12:00", "17:30"]  # 12:00と17:30にアラート
SOUND_PATH = r"SOUND_PATH"  # お好きなwav/mp3ファイルの絶対パス

def play_sound():
    try:
        pygame.mixer.init()
        pygame.mixer.music.load(SOUND_PATH)
        pygame.mixer.music.play()
    except Exception as e:
        print(f"音声再生エラー: {e}")

def show_time_and_play_sound(now):
    root = tk.Tk()
    root.attributes('-topmost', True)
    root.geometry("400x200+600+300")
    root.overrideredirect(True)
    label = tk.Label(root, text=now, font=("Arial", 60), fg="red")
    label.pack(expand=True)
    threading.Thread(target=play_sound, daemon=True).start()
    root.after(30000, root.destroy)
    root.mainloop()

def main():
    last_trigger_date = {t: "" for t in ALARM_TIMES}  # 各時刻ごとに管理
    while True:
        now = datetime.datetime.now()
        now_str = now.strftime("%H:%M")
        today_str = now.strftime("%Y-%m-%d")
        for alarm_time in ALARM_TIMES:
            if now_str == alarm_time and last_trigger_date[alarm_time] != today_str:
                show_time_and_play_sound(now_str)
                last_trigger_date[alarm_time] = today_str
        time.sleep(1)

if __name__ == "__main__":
    main()

exe化

pythonファイルをexe化します。
ここでnoconsoleにすることで、バックグラウンド風になります。

pip install pyinstaller
pyinstaller --onefile time_announcement.py --noconsole

スタートアップフォルダを開く

Windowsキー + Rを押した後、shell:startupを入力すると、スタートアップフォルダが開かれます。

image.png

スタートアップに登録

スタートアップフォルダにexe本体かそのショートカットを入れる。
これでWindows起動時に自動でファイルが実行されるようになります。

まとめ

私は基本的に出社していて、会社だとお昼や終業時間にチャイムが鳴るので、たまにテレワークすると時間に気づかないときがよくあります。そのため、今回はそこそこ実用的なものができたのではと思っています。

もし良ければ皆さんも実装してみてください!

8
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
8
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?