Pomodoro timer application using Python

 Introduction: 

The Pomodoro Technique is a time management method developed by Francesco Cirillo in the late 1980s. The technique uses a timer to break down work into intervals, traditionally 25 minutes in length, separated by short breaks.



CODE:

main.py



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
rept = 0
timer_v = None
# ---------------------------- TIMER RESET ------------------------------- #
def timer_cancle():
window.after_cancel(timer_v)
timer_txt.config(text="Timer")
canvas.itemconfig(timer_text, text="00:00")
check_mark.config(text="")
global rept
rept = 0

# ---------------------------- TIMER MECHANISM ------------------------------- #
def start():
global rept
rept += 1
short_break = SHORT_BREAK_MIN * 60
long_break = LONG_BREAK_MIN * 60
work = WORK_MIN * 60
if rept % 2 == 1:
timer(work)
timer_txt.config(text="Work", fg=GREEN)
elif rept % 2 == 0:
timer(short_break)
timer_txt.config(text="Break", fg=PINK)
if rept % 8 == 0 or rept == 9:
timer(long_break)
long_break_finished = True
timer_txt.config(text="Long Break", fg=RED)
if long_break_finished and rept == 9:
timer_txt.config(text="Congratulation", fg=GREEN)
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
def timer(count):
minute = math.floor(count / 60)
if minute < 10:
minute = f"0{minute}"
second = count % 60
if second < 10:
second = f"0{second}"
time_show = f"{minute}:{second}"
canvas.itemconfig(timer_text, text=time_show)
if count > 0:
global timer_v
timer_v = window.after(10, timer, count - 1)
elif rept <= 8:
start()
mark = ""
work_session = math.floor(rept/2)
for _ in range(work_session):
mark += "✔"
check_mark.config(text=mark)


# ---------------------------- UI SETUP ------------------------------- #
window = Tk()
window.config(padx=100, pady=50, bg=YELLOW)
window.title("Pomodoro Start")

canvas = Canvas(width=200, height=224, bg=YELLOW, highlightthickness=0)
tomato_image = PhotoImage(file="tomato.png")
canvas.create_image(100, 112, image=tomato_image)
timer_text = canvas.create_text(100, 130, text="00:00", fill="white", font=(FONT_NAME, 35, "bold"))
canvas.grid(column=1, row=1)


start_btn = Button(text="Start", highlightthickness=0, command=start)
start_btn.grid(column=0, row=2)

reset_btn = Button(text="Reset", highlightthickness=0, command=timer_cancle)
reset_btn.grid(column=2, row=2)

timer_txt = Label(text="Timer", bg=YELLOW, font=(FONT_NAME, 50), fg=GREEN)
timer_txt.grid(row=0, column=1)

check_mark = Label(text=" ", font=(FONT_NAME, 20), bg=YELLOW, fg=GREEN)
check_mark.grid(row=2, column=1)

window.mainloop()






Image

name: tomato.png
file dimension: 200 x 224



Comments

Popular posts from this blog

Where Does Intelligence Begin?

Random is not actually indeterministic, its hard to calculate.

Existence Game