0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

#AIアプリ100 002_PC作業中に一定間隔で姿勢矯正のアナウンス

Posted at

画面イメージ

image.png

PC作業を長時間していると姿勢が悪くなる、目が痛くなる、口呼吸になってしまうなどの生活上のリスクがあるので、これを回避するためのアプリをPythonで作成。
無意識だと姿勢がどんどん悪くなるので、勤務と同時に「開始」ボタンを押して一定の時間間隔で注意を促すポップアップが出てくる。

image.png

実行コード

import tkinter as tk
import threading
import time

class ReminderApp:
    def __init__(self, root):
        self.root = root
        self.root.title("生活習慣リマインダー")
        self.root.geometry("400x250")
        self.root.resizable(False, False)
        self.root.configure(bg="#F7F9FB")

        self.messages = [
            "🧘 姿勢を正しましょう(背筋を伸ばして、画面と目の高さを合わせて)",
            "👀 1分間、目を閉じて休めましょう(または遠くを見つめて)",
            "👃 鼻呼吸になっているか確認しましょう(深呼吸もおすすめです)"
        ]
        self.interval = 5  # 5秒ごとに表示(テスト用)
        self.running = False

        self.create_widgets()

    def create_widgets(self):
        tk.Label(self.root, text="PC作業習慣リマインダー", font=("Arial", 16, "bold"), bg="#F7F9FB").pack(pady=10)

        self.status_label = tk.Label(self.root, text="ステータス: 停止中", font=("Arial", 12), bg="#F7F9FB")
        self.status_label.pack(pady=5)

        self.start_button = tk.Button(
            self.root, text="▶ 開始", command=self.start_reminder, width=10,
            bg="#C8E6C9", fg="black", font=("Arial", 12)
        )
        self.start_button.pack(pady=5)

        self.stop_button = tk.Button(
            self.root, text="■ 停止", command=self.stop_reminder, width=10,
            bg="#FFCDD2", fg="black", font=("Arial", 12)
        )
        self.stop_button.pack(pady=5)

    def show_reminder(self, message):
        popup = tk.Toplevel()
        popup.title("リマインダー")
        popup.geometry("380x180+600+300")
        popup.configure(bg="#FFFBE7")
        popup.attributes('-topmost', True)

        tk.Label(popup, text="リマインダー", font=("Arial", 14, "bold"), bg="#FFFBE7").pack(pady=10)
        tk.Label(popup, text=message, wraplength=350, font=("Arial", 12), bg="#FFFBE7").pack(pady=10)
        tk.Button(popup, text="閉じる", command=popup.destroy, bg="#BBDEFB", fg="black").pack(pady=10)

    def reminder_loop(self):
        count = 0
        while self.running:
            time.sleep(self.interval)
            if self.running:
                msg = self.messages[count % len(self.messages)]
                self.root.after(0, lambda m=msg: self.show_reminder(m))
                count += 1

    def start_reminder(self):
        if not self.running:
            self.running = True
            self.status_label.config(text="ステータス: 実行中", fg="#4CAF50")
            threading.Thread(target=self.reminder_loop, daemon=True).start()

    def stop_reminder(self):
        self.running = False
        self.status_label.config(text="ステータス: 停止中", fg="#F44336")

if __name__ == "__main__":
    root = tk.Tk()
    app = ReminderApp(root)
    root.mainloop()

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?