Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DkGoat66 authored Mar 11, 2024
1 parent f513825 commit 5aef9c5
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,45 @@
LONG_BREAK_MIN = 20
reps = 0
timer = None

# ---------------------------- TIMER RESET ------------------------------- #
def reset_timer():
# Cancel the existing timer (if any)
window.after_cancel(timer)

# Reset the displayed timer text to "00:00"
canvas.itemconfig(timer_text, text="00:00")

# Reset the title label to "Timer"
title_label.config(text="Timer")

# Clear check marks
check_marks.config(text="")

# Reset the global reps counter to 0
global reps
reps=0
reps = 0

# ---------------------------- TIMER MECHANISM ------------------------------- #
def start_timer():
# Increment the reps counter
global reps
reps += 1

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

# Determine the type of timer (work or break) based on reps counter
if reps % 8 == 0:
count_down(long_break_sec)
title_label.config(text="Break",fg=RED,)
title_label.config(text="Break", fg=RED,)
elif reps % 2 == 0:
count_down(short_break_sec)
title_label.config(text="Break", fg=PINK)
else:
count_down(work_sec)
title_label.config(text="WorK", fg=GREEN)

title_label.config(text="Work", fg=GREEN)

# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
def count_down(count):
Expand All @@ -48,22 +59,25 @@ def count_down(count):
if count_sec < 10:
count_sec = f"0{count_sec}"

# Update the displayed timer text on the canvas
canvas.itemconfig(timer_text, text=f"{count_min}:{count_sec}")

# If there is time remaining, continue counting down
if count > 0:
global timer
timer = window.after(1000, count_down, count - 1)
else:
# If the countdown reaches 0, start the next timer
start_timer()

# Update check marks based on completed work sessions
mark = ""
work_session =math.floor(reps/2)
work_session = math.floor(reps / 2)
for _ in range(work_session):
mark +="✔"
mark += "✔"
check_marks.config(text=mark)


# ---------------------------- UI SETUP ------------------------------- #


window = Tk()
window.title("Pomodoro")
window.config(padx=100, pady=50, bg=YELLOW)
Expand Down

0 comments on commit 5aef9c5

Please sign in to comment.