top of page

Pomodoro alarm

  • Writer: 라임 샹큼
    라임 샹큼
  • Mar 30
  • 2 min read

import tkinter

from tkinter import PhotoImage


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

PINK = "#e2979c"

RED = "#e7305b"

GREEN = "#9bdeac"

YELLOW = "#f7f5dd"

FONT_NAME = "Courier"

# WORK_MIN = 25

# SHORT_BREAK_MIN = 5

# LONG_BREAK_MIN = 20

WORK_MIN = 0.1

SHORT_BREAK_MIN = 0.1

LONG_BREAK_MIN = 0.1

reps = 0

timer = None

# ---------------------------- TIMER RESET ------------------------------- # 

def reset_timer():

    global reps

    window.after_cancel(timer)

    reps = 0

    title.config(text='Timer', fg=GREEN)

    check_mark.config(text='')

    canvas.itemconfig(timer_text, text=f'00:00')


def raise_above_all(root):

    root.lift()

    root.attributes('-topmost', True)

def lower(root):

    root.after_idle(root.attributes, '-topmost', False)



# ---------------------------- TIMER MECHANISM ------------------------------- # 

def start_timer():

    global reps

    reps += 1

    work_min = int(WORK_MIN * 60)

    short_break = int(SHORT_BREAK_MIN * 60)

    long_break = int(LONG_BREAK_MIN * 60)


    if reps % 8 ==0:

        count_down(long_break)

        title.config(text = 'Break!',fg = RED)

        raise_above_all(window)

    elif reps %2 ==0:

        count_down(short_break)

        title.config(text = 'Break', fg = PINK)

        raise_above_all(window)

    else:

        count_down(work_min)

        title.config(text = 'Work', fg = GREEN)

        lower(window)



# ---------------------------- COUNTDOWN MECHANISM ------------------------------- # 

def count_down(count):

    count_min = int(count/60)

    count_sec = count % 60


    if count_sec == 0:

        count_sec = '00'

    elif len(str(count_sec)) == 1:

        count_sec = f'0{count_sec}'


    if count_min == 0:

        count_min = '00'

    elif len(str(count_min)) == 1:

        count_sec = f'0{count_min}'


    canvas.itemconfig(timer_text,text = f'{count_min}:{count_sec}')

    if count > 0:

        global timer

        timer = window.after(1000, count_down, count - 1)

    else:

        start_timer()

        check_num = int(reps / 2)

        check_mark.config(text = f'{'✔'*check_num}')

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

window = tkinter.Tk()

window.title('Pomodoro')

window.config(padx = 100, pady = 100, bg=YELLOW)


canvas = tkinter.Canvas(width=200, height = 224,bg=YELLOW,highlightthickness=0)

image = PhotoImage(file = 'tomato.png')

canvas.create_image(99, 112,image = image)

timer_text = canvas.create_text(99,130,text= '00:00',fill = 'white',font = (FONT_NAME,36,'bold'))

canvas.grid(column=1, row=1)


title = tkinter.Label(text='Timer', font=(FONT_NAME,40,'bold'),bg=YELLOW, fg=GREEN)

title.grid(column=1,row=0)


#start button

start_button = tkinter.Button(text='Start',highlightthickness=0, command = start_timer)

start_button.grid(column=0,row = 2)


#reset button

reset_button = tkinter.Button(text = 'Reset', highlightthickness=0,bg = YELLOW, command= reset_timer)

reset_button.grid(column = 2, row = 2)


check_mark = tkinter.Label(bg = YELLOW,fg = GREEN)

check_mark.grid(column = 1,row = 3)


window.mainloop()


What I learned

In tkinter, you can put image on screen like with turtle using the canvas widget

canvas = tkinter.Canvas()

img = Photoimage(file = filename)

canvas.create_image(x,y position, img)

canvas.pack()

 
 
 

Recent Posts

See All
Stock market price alerter

Lately I’ve been getting API data from existing data and using it to get actual live data. This is done by importing requests.  This was...

 
 
 
Making a better quiz ui

I reencountered classes again. I remember I had a a hard time learning how classes were different from simply defining functions. It was...

 
 
 
Getting quotes and displaying them

from tkinter import * import requests def get_quote():     quote_url = requests.get(url=' https://api.kanye.rest ')     quote_json =...

 
 
 

1 Comment


COP
COP
May 10

Calculate Your Age Instantly with Our Smart Age Calculator! 🧮

Ever wondered exactly how old you are — not just in years, but in months, days, hours, or even seconds? Our Age Calculator is the easiest and most accurate way to find out!

Whether you're planning a birthday party, tracking milestones, or just having fun with friends, our tool delivers precise results in real time. It's more than just a number — it's your life's timeline!

🔍 Why Use Our Online Age Calculator?

Instant & Accurate: Just input your date of birth, and get a detailed breakdown of your age in years, months, days, hours, minutes, and seconds — updated live.✅ No Hassle, No Sign-Up: Use it right away without creating…

Like

© 2024 by GifTED. Powered and secured by Wix

bottom of page