LoginSignup
0
2

More than 1 year has passed since last update.

Python + Tkinter - 学習時間を記録(ポモドーロ法)できるアプリ

Last updated at Posted at 2023-01-31

ポモドーロ法で学習時間を記録できるアプリ

Tkinter学習の一環でポモドーロ法で学習時間を記録できるアプリを制作しました。25分学習→5分休憩、という方法で効率よく仕事や学習を継続できるという学習法です。

スクリーンショット 2023-01-31 093939.png

コード

import tkinter as tk
from tkinter import *
import math

# ---------------------------- CONSTANTS ------------------------------- #

PINK = "#e2979c"
RED = "#e7305b"
GREEN = "#9bdeac"
YELLOW = "#f7f5dd"
FONT_NAME = "Courier"
WORK_MIN = 25
SHORT_BREAK_MIN = 5
LONG_BREAK_MIN = 20
reps = 0
timer = None

LEARNING_TEXT = "Work in Progress..."
BREAKING_TEXT = "Breaking Time!"
LONG_BREAKING_TEXT = "Congratulations! Done 2h of work. :)"
CHECK_TEXT = ""
check_string = ""

font_name = "Courier"


# スタートボタンの処理
#ボタンを押すとstart_timerを開始
def start():
    global reps
    global CHECK_TEXT
    reps +=1

    work_sec = WORK_MIN * 60
    short_break_sec = SHORT_BREAK_MIN * 60
    long_break_sec = LONG_BREAK_MIN * 60

    #4回サイクルをクリア後のカウント時間
    if reps % 8 == 0:
        count_down(long_break_sec)
        status_label.config(text=LONG_BREAKING_TEXT, fg=RED)
        CHECK_TEXT += check_string
        check_label.config(text=CHECK_TEXT)

    #偶数回時のカウント時間
    elif reps % 2 == 0:
        count_down(short_break_sec)
        status_label.config(text=BREAKING_TEXT, fg=RED )
        CHECK_TEXT += check_string
        check_label.config(text=CHECK_TEXT)

    #奇数回時のカウント時間
    else:
        count_down(work_sec)
        status_label.config(text=LEARNING_TEXT, fg=GREEN)


def count_down(count):
    global COUNT_STOP

    #小数点以下を切り捨て
    count_min = math.floor(count / 60)
    count_sec = count % 60

    #秒表示の文字数を調整
    if count % 60 < 10:
        count_sec = f"0{count_sec}"

    timer_text = f"{count_min}:{count_sec}"
    timer_label.config(text=timer_text)
    if count > 0:
        global timer
        timer = app.after(1000, count_down, count - 1)

    #秒数が0になったらタイマーを再スタート
    else:
        start()

def stop():
    global reps
    reps = 0

    app.after_cancel(timer)

    #全てのラベルをリセット

    title_label_text = "Pomodoro Timer"
    title_label.config(text = title_label_text)

    status_text = "Click \"start\" to began Pomodoro Timer:"
    status_label.config(text = status_text)

    timer_text = "00:00"
    timer_label.config(text = timer_text)

    check_text = ""
    check_label.config(text = check_text)



# メインウィンドウ作成
app = tk.Tk()
app.title("Pomodoro Timer")
app.minsize(width=500, height=400)
app.config(padx=50, pady=20)

#GUIにラベルを表示
title_label_text = "Pomodoro Timer"
title_label = tk.Label(app, text=title_label_text, font = ("Arial", 20, "bold"))
title_label.pack(pady = 10)

#GUIにラベルを表示( 学習中・休憩中 )
status_text = "Click \"start\" to began Pomodoro Timer:"
status_label = tk.Label(app, text=status_text, font = ("Arial", 18, "bold"))
status_label.config(fg= GREEN)
status_label.pack(pady = 5)

# 時間計測結果表示ラベル
timer_label = tk.Label(app,text="00:00",width=6, font=("", 50, "bold"))
timer_label.pack(padx=10, pady=10)

#GUIにラベルを表示( チェックマーク=ポモドーロ法回数 )
check_text = ""
check_label = tk.Label(app, text=check_text, font = ("Arial", 24, "bold"))
check_label.config(fg= GREEN)
check_label.pack(pady = 5)

# ストップウォッチのスタートボタン
start_button = Button(text="Start", font=(font_name, 20, "bold"), command = start)
start_button.pack(side="left")
start_button.pack(padx=75, pady=10)

# ストップウォッチのストップボタン
stop_button = Button(text="reset", font=(font_name, 20, "bold"), command = stop)
stop_button.pack(side="left")
stop_button.pack(padx=10, pady=10)

# メインループ
app.mainloop()
0
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
0
2