简体   繁体   English

未使用局部变量“计时器”值

[英]Local variable 'timer' value is not used

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".你好,我有这段代码,当定时器等于 10 时我想将它重置为 0。上面的代码不能正常工作,代码行“timer = 0”是说“局部变量'timer'值是不曾用过”。 I think is a Scope problem, but i'm not sure.我认为是 Scope 问题,但我不确定。

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? PS:我试图改变:计时器 = 0 和 window.after(1000, start, timer - 10) 并且正在工作......有人可以解释为什么这是工作吗? Thanks.谢谢。

This is not an error, this is a warning from your IDE.这不是错误,这是来自您的 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.在此行之后, timer = 0timer不再使用(您不会将它用于函数的 rest),因此您的 IDE 只是让您知道此分配给 0 有点毫无意义。 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.如果您的 function 的目标是在调用 function 后更改timer的值,您将遇到问题,因为 ZA7F5F35426B927411FC9231B563/82173Z 等类型使用了类似的传递文件。 will not be changed.不会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM