0
當我嘗試添加一個Label從.csv文件「arrowscore」檢索我遇到了錯誤的變量:Kivy添加窗口小部件的參數錯誤
TypeError: add_widget() missing 1 required positional argument: 'widget'
這是我的基本代碼:
class EvaluateScreen(Screen):
pass
class EvaluateLayout(BoxLayout):
global endNo
def update(stuff):
def readMe(endNo, i):
f = open("end" + str(endNo) + ".csv", "r") # opens the csv
lines = [line.rstrip('\n') for line in f] #reads the lines of the file
del lines[0] #removes the meta-value inside of the file
lines = lines[0] #extracts a 1d array (single line) from the lines
lines = lines.split(",") #splits the csv line into separate values in a list
print(lines) #for debugging purposes
f.close() # closes the file
return lines[int(i)] # returns the requested value
if canDrawScores == True: #if an external variable is true
for i in range(0,5): #for values 0 to 5
arrowScore = readMe(endNo, i)
BoxLayout.add_widget(Label(text=str(arrowScore))) #add a new label to the BoxLayout with text as the retrieved value
Clock.schedule_interval(update, 0.5) #checking if the external variable is true every half second
---編輯,但仍然是斷開---- 現在代碼是提高在self.do_layout一個AttributeError,指出「浮動」對象具有「do_layout」 類EvaluateScreen(屏幕)無屬性: 通
class EvaluateLayout(BoxLayout):
global endNo
global endLimit
def update(self):
self.do_layout()
def readMe(endNo, i):
f = open("end" + str(endNo) + ".csv", "r") # opens the end
lines = [line.rstrip('\n') for line in f] #reads the lines of the file
del lines[0]
lines = lines[0]
lines = lines.split(",")
print(lines)
f.close() # closes the file
return lines[int(i)] # returns the requested value
if canDrawScores == True:
for i in range(0,endLimit):
arrowScore = readMe(endNo, i)
self.add_widget(Label(text=str(arrowScore)))
Clock.schedule_interval(update, 0.5)
evaluatescreen = EvaluateScreen()
evaluatelayout = EvaluateLayout()
evaluatescreen.add_widget(evaluatelayout)
我已經得到了錯誤:「NameError:名字‘自我’沒有定義」即使它應該在啓動時被實例化。 – EtherealHawk
@ElealHawk - 我已經更新瞭解決更新定義的另一個問題的答案。你錯誤地將自己命名爲東西 –
這很奇怪我正在更新我的基本代碼,我已經重命名它,現在它在線上引發另一個錯誤self.do_layout() - AttributeError:'float'object has no attribute 'do_layout' – EtherealHawk