更新时间:2021-12-14 03:29:54
代替有十五个名为 c1
、c2
的变量... c15
,创建一个包含所有复选按钮的列表.对您的条目和变量执行相同的操作.
Instead of having fifteen variables named c1
, c2
... c15
, create a single list which will hold all of your checkbuttons. Do the same for your entries and vars.
checkbuttons = []
entries = []
vars = []
for i in range(numrec):
results = cursor.fetchone()
var = IntVar()
check_button=Checkbutton(frame1,variable=var)
check_button.grid(row=i,column=0,sticky='nw')
check_button.config(bg='black')
entry=Entry(frame1, bg="black", fg="white")
entry.grid(row=i, column=1, sticky=NW)
entry.delete(0, END)
for row in results:
entry.insert(END, *results)
checkbuttons.append(check_button)
entries.append(entry)
vars.append(var)
现在而不是得到例如e6
的第六个条目,您可以通过 entries[5]
获得它.
Now instead of getting e.g. the sixth entry with e6
, you get it with entries[5]
.