Local variable 'timer' value is not used

Viewed 33
def start(timer):
    global minuti
    canvas.itemconfig(second_text, text=f"0{timer}")
    window.after(1000, start, timer + 1)
    if len(str(timer)) < 2:
        print(timer)
        canvas.itemconfig(second_text, text=f"0{timer}")
    else:
        canvas.itemconfig(second_text, text=timer)
    if timer / 10 == 1:
        timer = 0     
        minuti = minuti + 1
        if len(str(minuti)) < 2:
            canvas.itemconfig(minute_text, text=f"0{minuti}")
        else:
            canvas.itemconfig(minute_text, text=minuti)

Hello, I have this code, and when the timer is equal to 10 I want to reset it to 0. The code above is not working properly, the line of code "timer = 0" is saying "Local variable 'timer' value is not used". I think is a Scope problem, but i'm not sure.

Can somebody help me??

PS: i've tried to change : timer = 0 with window.after(1000, start, timer - 10) and is working... Can somebody explain why this is working? Thanks.

1 Answers

This is not an error, this is a warning from your IDE. After this line, timer = 0, timer is not used again (you don't use it for the rest of the function) so your IDE is just letting you know that this assignment to 0 is sort of pointless. If your goal of this function is to have the value of timer change after the function is called you will have an issue because Python uses pass-by-sharing meaning mutable types like ints/floats/etc. will not be changed.

Related