#๐Ÿ”’ POMODORO CONTINUED

379 messages ยท Page 1 of 1 (latest)

muted forge
#

I'm building a pomodoro app and working on count down function. I don't know how to implement and need some guidance.

import tkinter as tk
import time

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

WORK_TIME = 25

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()
leaden sandBOT
#

@muted forge

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.

muted forge
#
WORK_TIME = 25

def count_down(total_seconds = None):
    # Set the work time into seconds
    if total_seconds is None:
        total_seconds = WORK_TIME * 60

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    # Update the label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
#
WORK_TIME = 25

def count_down(total_seconds = None):
    # Set the work time into seconds
    if total_seconds is None:
        total_seconds = WORK_TIME * 60

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    # Update the label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down, total_seconds - 1)
     
#

got it to count down

zenith bone
#

Doing it recursively might cause some problems later on.

muted forge
#

ohh?

zenith bone
#

Basically you're making the count_down() function call another instance of count_down().

#

Every time it does that it will increase the 'callstack' with another count_down() instance.

#

By the end of it you'll have 1500 instances of count_down running.

#

Not enough to cause a stack overflow or anything catastrophic. But it's good to keep it in mind.

muted forge
#

right right

#

how would i change that

zenith bone
#

You want that code to repeat x amount of times.

#

That's a loop's job, baybeh! ๐Ÿ˜Ž

muted forge
#

while total_seconds > 0?

zenith bone
#

That should work, yeah. I gotta head out, I have a test soon.

muted forge
#

okay good luck!

#
import tkinter as tk
import time

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

WORK_TIME = 25

def count_down(total_seconds = None):
    # Set the work time into seconds
    if total_seconds is None:
        total_seconds = WORK_TIME * 60

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    # Update the label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down, total_seconds - 1)
     

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()


im sticking with this solution for now because i dont know how to make it work with while loop

digital arrow
#

no, there is no recursion in there

muted forge
digital arrow
#

a recursion is a function that calls itself

#

here, you count_down doesn't call itself

#

it schedule the next call of the function

#

once the schedule is done, the functions ends

#

no stack

muted forge
#

okay

#

now a reset function

#
def reset_timer():
    pass
#

can i use if statement and automatically change the config back to 25:00?

muted forge
digital arrow
#

well you this function to change the next total_seconds sent to the count_down function back to WORK_TIME

#

so I suggest changing a little bit the code to store total_seconds somewhere and not using it as a parameter, but rather as a global variable

muted forge
#

can i use global total_seconds?

digital arrow
#

yes

#

you need to define total_seconds once, before

#

in the main program

muted forge
#
WORK_TIME = 25
global total_second
def count_down():
    # Set the work time into seconds
    if total_seconds is None:
        total_seconds = WORK_TIME * 60

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    # Update the label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down, total_seconds - 1)
#

oopsieeee

digital arrow
#

not like this, alright so I said: no more total_seconds argument
Let's fix this together

muted forge
#

yes please

digital arrow
#

now total_second is a global variable

#

which means, you define it in the main program

#

total_second = WORK_TIME

#

then, everytime you call count_down, you need to update the value

muted forge
digital arrow
#
WORK_TIME = 25
total_seconds = WORK_TIME * 60
def count_down():
    # decrease the counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    # Update the label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down)
#

By doing like this, you have total_second outside of the function

#

you don't want it to be only inside, bc you want to have access to it

#

now, you do

#

so you can easily reset it now, with a function doing


def reset():
  global total_seconds
  total_seconds = WORK_TIME*60
muted forge
#

total_second -= 1

#

that line

digital arrow
#

yeah typo

#

i fixed it

muted forge
#

so just repeat the countsown function

#

without the decrement?

digital arrow
#

the decrement happens in the function itself

muted forge
#
import tkinter as tk
import time

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

WORK_TIME = 25
total_seconds = WORK_TIME * 60
def count_down():
    # Decrease counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    #update label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down)
     
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)

def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

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

window.mainloop()

#

yay a bug

#

whenever i hit reset button, it automatically starts at 25

#

wait maybe not a bug

digital arrow
#

that's correct, isn't it ?

muted forge
#

its supposed to set it to 25 and then just stop there

#

instead of automatically start counting down again

#

unless im wrong

digital arrow
#

I guess that's correct

#

alright, so now, we need to change something in the code

#

you need a runnning and a pause mode

muted forge
#

did you change your teaching methods?

digital arrow
#

and a not_start mode

digital arrow
muted forge
#

you're explaining things and a lot more

#

i appreciate that a lot

digital arrow
#

idk I guess last time I had other things to do idk

#

right, back to it ?

muted forge
#

perhaps

#

yes yes

digital arrow
#

ok

muted forge
#

what does the running and pause mode do?

#

pause mode pauses the program

digital arrow
#

so, now, your timer is always decreasing

muted forge
#

the countdown

digital arrow
#

you want, given the mode, to do that

#

or not

#

in "not_started" mode, you want it to stay at 25 min

#

in "pause" mode, you want to not decrease the timer

#

and in "running" mode, you want to decrease the timer

muted forge
#

ok sure

#

more programming

#

more lessons to be learned

digital arrow
#

of course

#

a mode, basically, is a variable

#

that can be set to a few options

#

it can be some str, it can be some int, it can be whatever as soon as you know what it means

#

(more advanced user will use enums for that, but that's for later)

#

let's go with str

muted forge
#

so

digital arrow
#

At the beginning, when you start the app, what is the mode ?

muted forge
#

running

digital arrow
#

are you sure ?

muted forge
#

wait

#

its in pause mode

#

until u hit start

digital arrow
#

right

muted forge
#

then its running mode

digital arrow
#

the "not started" mode

muted forge
#

yes

digital arrow
#

right

#

so

#

a mode, is a variable

muted forge
#

mhmm

digital arrow
#

please, initialize a variable mode to the value "not started

muted forge
#
mode = "not started"

something tells me this isnt what u want

digital arrow
#

no that's good

#

now, we want:

  1. to set it to the correct mode when we hit the related button
  2. to make the timer behaves according to the mode
muted forge
#

yes sir!

digital arrow
#

let's start with 1), any idea ?

muted forge
#

when we hit start, mode changes to "started"

digital arrow
#

let's call it "running"

muted forge
#

yes

digital arrow
#

what about the other buttons ?

muted forge
#

when we hit reset, mode changes to not_running

#

or simply reset

digital arrow
#

"not started"

muted forge
#

okay

digital arrow
#

the third is "pause"

muted forge
#

yes

digital arrow
#

which will become an unpause button once hit

#

let's focus on "running" and "not started"

#

can you write the function that the "start" button will call ?

muted forge
#

ofc

#
def start():
    pass
#

as such?

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

but command points to count down

digital arrow
#

what's the point of that

#

alright so now, when you start, you don't only want to start the count down

#

you also want to change the mode

muted forge
#

i didnt understand what you meant sorry

#

i still dont aha

digital arrow
#

you are in mode "not started"

#

when you hit the "start" button

#

you need to change the mode

#

and start the cooldown

muted forge
#
def start():
    
    mode = "started"
#

please dont give up on me :/

#

can you give me hints

#
def start():
    
    mode = "started"
    count_down()
digital arrow
#

better

#

close

muted forge
#

ayeeee

digital arrow
#

remember that mode is a global variable

muted forge
#

def start():
global mode
mode = "started"
count_down()

leaden sandBOT
#

Hey @muted forge!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
muted forge
#
def start():
    global mode 
    mode = "started"
    count_down()

digital arrow
#

if you do that, python do not know you want to modify the global one and will create a new one

#

yep

#

correct

muted forge
#

dopamine hit lets goo

digital arrow
#

now the button

muted forge
#

pardon? what about the button?

digital arrow
#

can you write the code for the button ?

muted forge
#
start_button = tk.Button(
    window,
    text="Start",
    font=("Consolas", 14),
    command= count_down
)
``` you mean this? or what do you mean?
digital arrow
#

yes this

#

you know what is the command of the button ?

muted forge
#

add another command which points to stat?

#

start?

digital arrow
#

command is the function that is called when you hit the button

#

you can have only one command

muted forge
#

ohh

#

im confused as to what you're asking me to do now

#

ohh wait

#
import tkinter as tk
import time

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

mode = "not started"
WORK_TIME = 25
total_seconds = WORK_TIME * 60
def count_down():
    # Decrease counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    #update label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down)
     
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= start
)
start_button.pack(pady=5)

def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

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

def start():
    global mode 
    mode = "started"
    count_down()

window.mainloop()

#

i have the countdown function within start function

#

so i can jsut change the command to start?

#

maybe not its giving me error

digital arrow
#

what error ?

muted forge
#

i think start function needs to be above the start_button

digital arrow
#

yes

muted forge
#

okay the above code is wht i have so far

digital arrow
#

alright, does it work ?

#

does it start the timer when you hit the button ?

muted forge
#

yes siirrr

#

but another bug

#

when i hit start multiple times, it messes up the timer

digital arrow
#

makes sense

#

let's think about it: when the timer is running, do you want the start button to still appear on screen ?

muted forge
#

yes

#

at least thats what the app does

#

that i sent couple of days ago

#

actually it

#

when i hit start, it changes to pause

digital arrow
#

right, no need for a start button if it is running

muted forge
#

lets keep it simple

#

since we are programming python

#

kiss keep it simple

#

lets keep the start button for now

digital arrow
#

python can do great things

muted forge
#

and we can change it later

digital arrow
#

removing a button isn't difficult yk

muted forge
#

oh?

digital arrow
#

alright

#

what we could do is disabling it

muted forge
#

okay

digital arrow
#

I'll let you search how can a button in tkinter be disabled

muted forge
#

okay

#

state = disabled

#

does that mean we need state = normal in the countdown function?

digital arrow
#

by default it's normal

#

and no, not in the countdown function

#

the countdown only... counts down

muted forge
#

okay

digital arrow
#

it doesn't matter for this function if the button start is disabled or not

#

however, you need to think "when do I need to disable the button ?"

muted forge
#
def start():
    global mode 
    mode = "started"
    start_button.config(state="disabled")
    count_down() 

digital arrow
#

alright

#

let's test it

muted forge
#

works

digital arrow
#

nice

#

now, the reset

muted forge
#

keeps the start disabled

digital arrow
#

for now yes

muted forge
#
def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    start_button.config(state="active")
#

works

digital arrow
#

the reset buttons needs to:

  • change the state to "not started"
  • enable the start button
  • disable the reset button (and the start button should enable it)
digital arrow
muted forge
#
import tkinter as tk
import time

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

mode = "not started"
WORK_TIME = 25
total_seconds = WORK_TIME * 60
def count_down():
    # Decrease counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    #update label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down)
     
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)

def start():
    global mode 
    mode = "started"
    start_button.config(state="disabled")
    count_down() 


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

def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
    reset_button.config(state="disabled")
    start_button.config(state="active")

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

 

window.mainloop()


 

#

my brain is fried ngl

#

when one button is disabled, other should be active right?

digital arrow
#

"normal"

#

not "active"

#

double check that on tkinter documentation

muted forge
#
import tkinter as tk
import time

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

mode = "not started"
WORK_TIME = 25
total_seconds = WORK_TIME * 60
def count_down():
    # Decrease counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    #update label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down)
     
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)

def start():
    global mode 
    mode = "started"
    start_button.config(state="disabled")
    count_down() 


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

def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
    reset_button.config(state="disabled")
    start_button.config(state="normal")

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

 

window.mainloop()


 

#

ill start commenting where i made the changes from now on

#

so its easier for you

digital arrow
#

you can also only share the part that you changed

#

that's easier for everyone

muted forge
#

true

#

ahahaa

digital arrow
#

anyway, I assume this is not working as expecting, as the count_down still... counts_down

#

right ?

muted forge
#

yes

digital arrow
#

even after resetting

muted forge
#

wait

#

yes

digital arrow
#

alright, so what happens is:
when the cool down function is executing, it schedule its next call. but when we hit reset, we don't want to call again

#

we want to stop

#

so what do you propose ?

muted forge
#

not quite sure

#

something after the if statement tht disables the countdown schedule

#
if total_seconds > 0:
        window.after(1000, count_down)
#

here

digital arrow
#

something there, yes

#

so, what variable do you have that can be used to know in which mode we are ?

muted forge
#

mode

digital arrow
#

alright

muted forge
#
if total_seconds > 0 and mode=="started":
        window.after(1000, count_down)
    else:
        pass
#

do i have the right idea?

digital arrow
#

looks good, you don't need the else: pass

#

no purpose

#

alright so now, let's try it

muted forge
#

my brain is fried dude

#

i forgot the problem we were working on

#

ahahah

#

ok

#

so its still countdowning even after resetting

digital arrow
#

is it ?

muted forge
#
def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
    reset_button.config(state="disabled")
    start_button.config(state="normal")

maybe change the mode here?

digital arrow
#

of course

muted forge
#

am i overcomplicating?

digital arrow
#

I forgot about that

#

of course change the mode here

muted forge
#
def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
    reset_button.config(state="disabled")
    start_button.config(state="normal")
    mode = "reset"
#

nope doesnt fix it

digital arrow
#

okay what are the modes we have ?

#

list them

muted forge
#

    if total_seconds > 0 and mode=="started":
        window.after(1000, count_down)
``` maybe something wrong here
#

running, not started, started

digital arrow
#

Uhm so we don't have a running mode, it's named started
also, then what's that:

mode = "reset"

muted forge
#

ohh right i just added that

#

so started, not started, reset

digital arrow
#

what's the difference between "not started" and "reset" ?

muted forge
#

dont know :/

#

same?

digital arrow
#

you tell me

muted forge
#

not started is before anything runs

#

reset is when user pressed stop the countdown

digital arrow
#

ok but what's the difference between both ?

muted forge
#

nothing

#

i think its the same

digital arrow
#

right, so let's simplify it

#

if two modes are the same

#

it's the same mode

#

let's not have different words for the same thing

muted forge
#

ofc

#

apologies

digital arrow
#

so when you reset, you set the mode to "not started"

muted forge
#

did

#
def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
    reset_button.config(state="disabled")
    start_button.config(state="normal")
    mode = "not started"
digital arrow
#

working now ?

muted forge
#

no sir

digital arrow
#

still decreasing ?

muted forge
#

yes

digital arrow
#

can you copy paste your whole code here

#

I'll try it

muted forge
#
import tkinter as tk
import time

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

mode = "not started"
WORK_TIME = 25
total_seconds = WORK_TIME * 60
def count_down():
    # Decrease counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    #update label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0 and mode=="started":
        window.after(1000, count_down)
     
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)

def start():
    global mode 
    mode = "started"
    start_button.config(state="disabled")
    count_down() 


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

def reset_timer():
    global total_seconds
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
    reset_button.config(state="disabled")
    start_button.config(state="normal")
    mode = "not started"

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

 

window.mainloop()


 

digital arrow
#

right I got the issue

#

there is something you do in the start function that you forget to do in the reset_timer one

#

it's about global variables

muted forge
#
def reset_timer():
    global total_seconds
    global mode
    total_seconds = WORK_TIME * 60

    # Update label to show full time again
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)
    reset_button.config(state="disabled")
    start_button.config(state="normal")
    mode = "not started"
#

global mode?

digital arrow
#

try it

muted forge
#

doesnt work

digital arrow
#

you can simplify by
global total_seconds, mode

#

are you sure ?

muted forge
#

yes sir

digital arrow
#

I tried it, and the only issue now is the timer sets to 25:00, then it goes down to 24:59 and stops

#

do you have that ?

muted forge
#

yes

digital arrow
#

alright, so let's see the count_down again

muted forge
#

i greatly appreciate your help btw

#

im grateful

digital arrow
#

What happens is that when you hit the "reset" button, there is still a call of the function that is scheduled.
What we did, is that when this call is done, if we are in "not started" mode, then we don't schedule the next one

#

but we would like to also avoid decreasing the counter

muted forge
#

yes

digital arrow
#
def count_down():
    # Decrease counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    #update label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0 and mode=="started":
        window.after(1000, count_down)

this is now

#

but we don't want the first part of the function to be executed if we are not in "started" mode, right ?

muted forge
#

put that in the if statement?

#

yes

digital arrow
#

not in THE if statement

#

in another if statement

muted forge
#

how so?

digital arrow
#

write one

#

the first part (the whole thing in fact) should not happen when you are in "not started" mode

#

I think you can translate that into python quite easily

#

(last thing for today then if it's work I go to sleep)

muted forge
#

yes sure i need a break too

#

if count_down > 0:
total_seconds -=1

#

idk wht condition to put

digital arrow
#

let me rephrase

#

in "not started" mode, the function doesn't do anything

muted forge
#
def count_down():
    # Decrease counter
    global total_seconds
    
    if total_seconds > 0 and mode=="started":
        window.after(1000, count_down)
        # compute min and sec
        minutes = total_seconds // 60
        seconds = total_seconds % 60

        #update label
        formatted_time = f"{minutes:02d}:{seconds:02d}"
        time_label.config(text=formatted_time)

    total_seconds -= 1
#

brooo idk what i did

digital arrow
#

in "started" mode, it does what it is already doing
(which is the following thing)

    # Decrease counter
    global total_seconds
    total_seconds -= 1

    # compute min and sec
    minutes = total_seconds // 60
    seconds = total_seconds % 60

    #update label
    formatted_time = f"{minutes:02d}:{seconds:02d}"
    time_label.config(text=formatted_time)

    if total_seconds > 0:
        window.after(1000, count_down)
muted forge
#

but it works

digital arrow
#

okay yeah it visually works but your counter is still decreasing

#

even when you are not started

muted forge
#
def count_down():
    # Decrease counter
    global total_seconds
    
    if total_seconds > 0 and mode=="started":
        window.after(1000, count_down)
        # compute min and sec
        minutes = total_seconds // 60
        seconds = total_seconds % 60

        #update label
        formatted_time = f"{minutes:02d}:{seconds:02d}"
        time_label.config(text=formatted_time)

        total_seconds -= 1
#

whatabout now

digital arrow
#

ye

muted forge
#

LETS GOOO

#

OK WE CAN PAUSE HERE

digital arrow
#

alright

#

time to rest

muted forge
#

i greatly greatly appreciate your help!

digital arrow
#

No problem

muted forge
#

do you work as a python dev?

digital arrow
#

next step is make a pause and unpause button

#

I am a data scientist

muted forge
#

would a math major and self taught python be the route to ds?

#

or just major in ds

digital arrow
#

focus on stats and optimization and that could do

#

better to major in DS but doesn't mean the door is close

muted forge
#

if i want to get into ai?

#

nvm i wanna stick with math

digital arrow
#

same

muted forge
#

and then i can specialize

#

well

#

sleep tight!

digital arrow
#

thanks

#

bye !

muted forge
#

!closw

leaden sandBOT
#
Did you mean:

!close

muted forge
#

!close

leaden sandBOT
#
Python help channel closed with !close

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.