我正在开发一个 tkinter 项目,并且在使用 for 循环创建多个按钮时遇到问题。当我尝试在循环中创建按钮时,我收到错误“列表”对象没有属性“tk”。我正在使用从 db 浏览器中的表生成的两个列表,如下所示。第二部分是发生错误的地方。如果我删除了 RewardButton 生成器,则不会发生错误,因此我认为此特定行存在问题
conn = sqlite3.connect("Scheduling.db")
c = conn.cursor()
c.execute("select reward from rewards where Cu_ID=?",(ID))
rewards = c.fetchall()
c.execute("select points from rewards where Cu_ID=?",(ID))
points = c.fetchall()
c.close()
rewardlist=[]
for l in rewards:
rewardlist.append(l)
pointlist=[]
for p in points:
pointlist.append(p)
buttonnum=len(rewardlist)
for x in range(buttonnum):
rowpos = x+5
reward = rewardlist[x]
point = pointlist[x]
RewardButton[x] = Button(rewards, text ="Button",command = lambda k=x: RedeemReward(k))
RewardButton[x].grid(row=rowpos, column=3)