如何得到动态生成控件的名字

小白一枚,准备用动态生成31个frame,每个frame中再放置Label、Text窗口部件,如何得到动态生成控件的名字,后续还要访问?

for i in range(31):

fm[i]=Frame(height=200, width=200, bg='green',border=2)
fm[i].place(x=i*200,y=100)#
Label(fm[i], text=str(i).pack(side='top')
...

难道要一个一个

fm_1=Frame(height=200, width=200, bg='green',border=2)
fm_1.place(x=0,y=100*yy)#
Label(fm_1, text='1'.pack(side='top')

fm_2=Frame(height=200, width=200, bg='green',border=2)
fm_2.place(x=200,y=100*yy)#
Label(fm_2, text='2'.pack(side='top')

...

阅读 2.3k
1 个回答

你已经知道答案了,你的loop 里面的 fm[i] 就是每个 Frame .

fm[1]=Frame(height=200, width=200, bg='green',border=2)
fm[1].place(x=0,y=100*yy)#
Label(fm[1], text='1'.pack(side='top')

fm[2]=Frame(height=200, width=200, bg='green',border=2)
fm[2].place(x=200,y=100*yy)#
Label(fm[2], text='2'.pack(side='top')
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题