3
我試圖用configure方法更改我的應用程序的標籤。標籤是在for循環中動態生成的。這裏是代碼的一部分:Tkinter:動態生成標籤的配置方法
# create a list of reference for labels equal to zero
self.lbl_areas = []
for i in range(0, len(self.samples)): # number of labels
lbl=tk.IntVar()
lbl.set(0)
self.lbl_areas.append(tk.Label(self.win,textvariable=lbl))
# Place labels on the application using grid
for i,v in enumerate(self.lbl_areas):
v.grid(row=2+i,column=1,sticky=tk.W)
# Try to change the value
for i in range(0, len(self.samples)):
self.lbl_areas[i].configure(textvariable=lbl_val[i]) # other values
顯示默認的零值,但配置方法似乎不起作用。我做錯了什麼?
工作正常。非常感謝你!我將使用第二個選項:更改標籤文本。 – diegus