You should not be using exec
. If you want to associate a computed name with a widget in a loop, use a dictionary:
labels = {}
varnum = 0
for row in crsr.fetchall():
name=f"label#{varnum}"
labels[name] = tk.Label(frame, text=str(row[0]))
labels[name].grid(row=row_num, column=column_num
varnum += 1
row_num+=1
column_num+=1
If you don't really care what the name is, you can store the widgets in a list rather than a dictionary, and then reference them using an integer index (eg: labels[0]
, labels[1]
, etc).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…