我正在尝试创建Button
并在屏幕上显示列表。
我有打印列表"matching"
的代码并显示正确的列表,但是当它显示按钮时,只有列表中的最后一项显示在屏幕上作为按钮。
self.db
,当打印到屏幕`时将整个列表显示为按钮组件,但同样,屏幕上只显示最后一个。
一直在寻找和尝试不同的事情几个小时,但无法弄清楚它为什么会这样。
这是我的代码:
def GatherAndDisplay(self) :
"""grabs the file and loads into memory to display"""
SearchData = TCT.ReadData("FullProgramTest.csv")
ntsf = self.ns.get()
matching = [s for s in SearchData if ntsf in s]
self.db = []
for c in matching:
print(self.db) #just used this to see if the list was being updated
self.db.append(tk.Button(self.top2, text = str(c)))
self.db[-1].grid(row = 6, column = 1, sticky = W)