#πŸ”’ Pomodoro Continued

57 messages Β· Page 1 of 1 (latest)

wind quiver
#

Implementing the countdown logic. How do I get started on it?

import tkinter as tk
window = tk.Tk()
window.title("Pomodoro")
window.geometry("500x500")

def countdown():
    pass


title_label = tk.Label(
    window,
    text="Pomodoro Timer",
    font=("Consolas", 30, "bold"),
    bg="white",
    fg="black"
)
title_label.pack(pady=20)

time_label = tk.Label(
    window,
    text="00:00",
    font=("Consolas", 48, "bold"),
    bg="white",
    fg="black"

)
time_label.pack(pady=10)


start_button = tk.Button(
    window,
    text="Start",
    font=("Consolas", 14),
    command= None
)
start_button.pack(pady=5)

reset_button = tk.Button(
    window,
    text="Reset",
    font=("Consolas", 14),
    command=None
)
reset_button.pack(pady=5)

window.mainloop()


 
verbal boneBOT
#

@wind quiver

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

potent fog
#

Baby steps:

1- make the start button call the countdown command

2- import the time lib

3- ???

4- Profit

wind quiver
#

how to do 1?

potent fog
#

There are many approaches you can use to implement the countdown logic.
Most of them involve putting some code inside a while loop.

potent fog
wind quiver
#

im confused broski

potent fog
#

In the start button

wind quiver
#
import tkinter as tk
import time

window = tk.Tk()
window.title("Pomodoro")
window.geometry("500x500")

def count_down():
    pass

title_label = tk.Label(
    window,
    text="Pomodoro Timer",
    font=("Consolas", 30, "bold"),
    bg="white",
    fg="black"
)
title_label.pack(pady=20)

time_label = tk.Label(
    window,
    text="00:00",
    font=("Consolas", 48, "bold"),
    bg="white",
    fg="black"

)
time_label.pack(pady=10)


start_button = tk.Button(
    window,
    text="Start",
    font=("Consolas", 14),
    command= count_down()
)
start_button.pack(pady=5)

reset_button = tk.Button(
    window,
    text="Reset",
    font=("Consolas", 14),
    command=None
)
reset_button.pack(pady=5)

window.mainloop()
potent fog
#

As for right now, set the logic inside the count_down to be just a print('test') to check if it's working.

wind quiver
#

it is

#

it prints out hello world in the terminal

split fox
#

you have only coded the GUI the graphical user interface, but the logic behind "count" is missing πŸ˜‰

potent fog
#

Indeed. Let's get started on that.

wind quiver
#

mhmm

potent fog
#

Lets just start with a 25 minute timer then expand it further.

wind quiver
#

yes

#

make a constant 25?

#

variable?

potent fog
#

Yes. Create a variable that keeps track of how many seconds are remaining.

wind quiver
#

WORK_TIME = 25

def count_down():
    print("Hello World")
split fox
#

What This Code Does:
Creates a window with title "Pomodoro" and dimensions 500x500 pixels
Sets up labels for the title ("Pomodoro Timer") and time display ("00:00")
Creates Start and Reset buttons, but they're incomplete
Issues Identified:
count_down() function is empty - it's just a placeholder with pass
Start button command incorrectly calls function: command=count_down() instead of command=count_down (notice the parentheses)
Reset button has no command assigned
No actual timer logic implemented

wind quiver
#

broo i dont need that ai junk

#

i appreciate the help tho

potent fog
#

Then a while loop that;
1- converts that many seconds into a usable MM:SS string
2- updates the time display text with that string
3- decreases the amount of time remaining by 1
4- pauses the program for a second

split fox
#

if that does not help you ... you are fare more away from programming ... like ^^
i know i am not a coder but i have a brain πŸ˜‰

potent fog
#

For item number 4 you can use time.sleep(1) otherwise python will just blaze through the while loop unimpeded

wind quiver
#
WORK_TIME = 25

def count_down():
    seconds = 25 * 60
#

how would i update the time display with string?

#

2?

#

#2?

potent fog
#

You assigned a tk.Label with a property text="00:00" to a variable time_label

wind quiver
#

how would i do it within the function though

potent fog
#

Wait, let me review the docs.

#

It would be time_label.config(text= *insert new string here*)

wind quiver
#
import tkinter as tk
import time

window = tk.Tk()
window.title("Pomodoro")
window.geometry("500x500")

WORK_TIME = 25

def count_down():
    seconds = 25 * 60
    time_label.config(text=seconds)

title_label = tk.Label(
    window,
    text="Pomodoro Timer",
    font=("Consolas", 30, "bold"),
    bg="white",
    fg="black"
)
title_label.pack(pady=20)

time_label = tk.Label(
    window,
    text="00:00",
    font=("Consolas", 48, "bold"),
    bg="white",
    fg="black"

)
time_label.pack(pady=10)


start_button = tk.Button(
    window,
    text="Start",
    font=("Consolas", 14),
    command= count_down
)
start_button.pack(pady=5)

reset_button = tk.Button(
    window,
    text="Reset",
    font=("Consolas", 14),
    command=None
)
reset_button.pack(pady=5)

window.mainloop()


 
#

WORK_TIME = 25

def count_down():
    seconds = WORK_TIME * 60
    time_label.config(text=seconds)
potent fog
#

Remember those 4 items need to be inside a while loop

wind quiver
#

no idea how to implement that

potent fog
#

How would you go about putting 1000 seconds remaining in a XX:XX string format?

#

Which is to say, how many minutes remaining is that? How many seconds?

wind quiver
#
total_seconds = 1000

minutes = total_seconds // 60
seconds = total_seconds % 60

formatted_time = f"{minutes:02d}:{seconds:02d}"
potent fog
#

Cool, that's item 1

wind quiver
#
def count_down():
    total_seconds = WORK_TIME * 60

    minutes = total_seconds // 60
    seconds = total_seconds % 60

    formatted_time = f"{minutes:02d}:{seconds:02d}"
#

as so/

#

?

potent fog
#

Put everything below the line total_seconds in a while loop. You'll need to execute that every second.

wind quiver
#

while loop

#

what condition

#
WORK_TIME = 25

def count_down():
    total_seconds = WORK_TIME * 60
    while total_seconds > 0:
        minutes = total_seconds // 60
        seconds = total_seconds % 60
potent fog
#

Yup

wind quiver
#

im gonna take a break here

#

i been at it for like 3 hrs or more

potent fog
#

That's alright. You've done item 1. Now just need 2-4

wind quiver
#

thank you!

verbal boneBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.