栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Tkinter:for循环创建的Addressing Label小部件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tkinter:for循环创建的Addressing Label小部件

当然!只需列出一个标签列表,调用

place
每个标签,然后您便可以稍后引用它们并更改其值。像这样:

from Tkinter import *root=Tk()sizex = 600sizey = 400posx  = 0posy  = 0root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))labels = []def myClick():    del labels[:] # remove any previous labels from if the callback was called before    myframe=frame(root,width=400,height=300,bd=2,relief=GROOVE)    myframe.place(x=10,y=10)    x=myvalue.get()    value=int(x)    for i in range(value):        labels.append(Label(myframe,text=" mytext "+str(i)))        labels[i].place(x=10,y=10+(30*i))        Button(myframe,text="Accept").place(x=70,y=10+(30*i))def myClick2():    if len(labels) > 0:        labels[0].config(text="Click2!")    if len(labels) > 1:        labels[1].config(text="Click2!!")mybutton=Button(root,text="OK",command=myClick)mybutton.place(x=420,y=10)mybutton2=Button(root,text="Change",command=myClick2)mybutton2.place(x=420,y=80)myvalue=Entry(root)myvalue.place(x=450,y=10)root.mainloop()

另请注意!在

Mylabel=Label(myframe,text=" mytext"+str(i)).place(x=10,y=10+(30*i))
原始代码的分配中,该调用设置
Mylabel
为None,因为该
place
方法返回None。您希望将
place
调用分成单独的一行,就像上面的代码一样。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624183.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号