Home > Net >  Python Replit Error: AttributeError: 'function' object has no attribute 'update'
Python Replit Error: AttributeError: 'function' object has no attribute 'update'

Time:11-18

I'm having this problem with this snippet of code:

    def countdown():
        global rem_time
        global clock
        global pause
        if rem_time > 0 and pause == False:
            rem_time -= 1
            clock()
            #time.sleep(1)
            timer.update()
            timer.after(1000, countdown)

This works on an IDE on my pc but when i upload it to Replit it comes back with the error: AttributeError: 'function' object has no attribute 'update'

Has something happened with my code when copied across or is the Replit IDE bugged?

Here is my full code for context (mass amount of buttons have been removed due to code:detail limit):

from tkinter import *
import time

timer = Tk()
timer.title("Timer")

rem_time = 0

rem_h = 0
rem_m = 0
rem_s = 0

pause = False

scr_width = int(timer.winfo_screenwidth())
scr_height = int(timer.winfo_screenheight())

timer.geometry(str(scr_width) "x" str(scr_height))

global adjust

def pauseFunc():
    global pause
    global Pause
    if pause == False:
        pause = True
        #Pause.config(text="Resume timer")
        Pause["text"]="Resume timer"
    if pause == True:
        pause = False
        #Pause.config(text="Pause timer")
        Pause["text"]="Pause timer"

def clock():
    global rem_time
    global rem_h
    global rem_m
    global rem_s
    global Hrs
    global Mins
    global Secs
    total = rem_time
    rem_h = total // 3600
    rem_m = (total - (rem_h*3600)) // 60
    rem_s = (total - ((rem_m*60) (rem_h*3600)))
    real = True
    while real == False:
        real = True
        if rem_h < 0:
            rem_h=0
            real = False
        if rem_m < 0:
            rem_m=0
            real = False
        if rem_s < 0:
            rem_s=0
            real = False
    #Hrs = Label(timer, font=("helvetica", 20, "bold"), text=str(rem_h) ":", bg="white").place(x=40, y=130)
    #Mins = Label(timer, font=("helvetica", 20, "bold"), text=str(rem_m) ":", bg="white").place(x=110, y=130)
    #Secs = Label(timer, font=("helvetica", 20, "bold"), text=str(rem_s) ":", bg="white").place(x=180, y=130)
    Hrs.config(text=str(rem_h) ":")
    Mins.config(text=str(rem_m) ":")
    Secs.config(text=str(rem_s))

def adjust(hours, minutes, seconds):
    global rem_time
    global clock
    rem_time  = seconds (minutes*60) (hours*3600)
    if rem_time <= 0:
        rem_time = 0
    clock()
        
def reset():
    global clock
    global rem_time
    rem_time = 0
    clock()
    
def countdown():
    global rem_time
    global clock
    global pause
    if rem_time > 0 and pause == False:
        rem_time -= 1
        clock()
        #time.sleep(1)
        timer.update()
        timer.after(1000, countdown)

timer.mainloop()

CodePudding user response:

Check your imports. Replit thinks timer is a function, and functions don't have an attribute called update. On your IDE you probably import a module called timer with this property.

CodePudding user response:

I don't know why but Relpit wants to global the timer and the function inside itself to work

  • Related