我正在尝试使用textvariable(python3)来更改Label小部件的文本,我得到.... NameError:name' w01'未定义
from tkinter import *
import time
def dofunc():
w01.config(text='ok1')
root = Tk()
w_id = ['w01','w02','w03','w04','w05']
for i in range(5):
print('print >> ',w_id[i])
w_id[i] = StringVar()
w=Label(root,width=5,textvariable=w_id[i])
w.pack()
root.geometry("+50+50")
root.after(500, dofunc)
root.mainloop()
答案 0 :(得分:0)
我想你应该喜欢这个
w_id = []
for i in range(5):
v= StringVar()
w=Label(root,width=5,textvariable=v)
w_id.append(v)
w.pack()