![](/img/trans.png)
[英]Python Error: AttributeError: 'builtin_function_or_method' object has no attribute
[英]Python Replit Error: AttributeError: 'function' object has no attribute 'update'
我在这段代码中遇到了这个问题:
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)
这适用于我电脑上的 IDE,但是当我将它上传到 Replit 时,它返回错误: AttributeError: 'function' object has no attribute 'update'
复制时我的代码是否发生了问题,或者 Replit IDE 是否被窃听?
这是我的完整上下文代码(由于代码:细节限制,大量按钮已被删除):
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()
检查您的进口。 Replit 认为timer
是一个函数,而函数没有一个叫做update
的属性。 在您的 IDE 上,您可能会使用此属性导入一个名为timer
的模块。
我不知道为什么,但 Relpit 想要全局计时器和它内部的函数来工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.