我在這段代碼中遇到了這個問題:
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()
uj5u.com熱心網友回復:
檢查您的進口。Replit 認為timer是一個函式,而函式沒有一個叫做 的屬性update。在您的 IDE 上,您可能會匯入一個timer使用此屬性呼叫的模塊。
uj5u.com熱心網友回復:
我不知道為什么,但 Relpit 想要全域計時器和它內部的函式來作業
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/358527.html
