![](/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.