[英]tkinter present the values from a list to entry widgets
Using tkinter in the gui I'm building an array made of entry boxes. 在gui中使用tkinter,我正在构建一个由输入框组成的数组。 In some columns of the array I'm entering values which i read them and build a list for every column.
在数组的某些列中,我输入要读取的值并为每列建立一个列表。 There are also columns without values which are readonly in which I want to export results from lists.
也有一些没有值的列,这些列是只读的,我想从列表中导出结果。 I can't find how to make the program to show the results.
我找不到如何使程序显示结果的方法。
Keep in mind that i have two defs one for building the widgets and one for the calculations. 请记住,我有两个定义,一个用于构建小部件,另一个用于计算。
In order to build one empty-results column I make this: 为了建立一个空结果列,我这样做:
self.akt_b =[]
for i in range(12):
akt_b =StringVar()
self.akt_b =Entry(self, textvariable =akt_b, width =10,
state='readonly', readonlybackground ="white")
self.akt_b.grid(row =7+i, column =3)
which makes visually what I want. 从视觉上看,我想要什么。 Then I calculate a list_b of 12 float numbers which I want to show in self.akt_b I'm trying:
然后我计算出要在self.akt_b中显示的12个浮点数的list_b,我正在尝试:
for i in range(12):
self.akt_b[i+1].delete(0, END)
self.akt_b[(i+1)].set("round(list_b[(i+1)], 2)")
which doesn't work I've tried also .insert not again, I've tried akt_b nothing again 这不起作用,我也尝试过.insert,我再次尝试akt_b
what can I do? 我能做什么?
after Kevin's answer I found out the solution, I was missing the .append argument. 在凯文(Kevin)的答案之后,我找到了解决方案,但我错过了.append参数。
Just in case anyone is interested here is the solution: 以防万一有人对这里感兴趣的是解决方案:
self.akt_b, self.entries =[], []
for i in range(12):
akt_b =StringVar()
entries =Entry(self, textvariable =akt_b, width =10,
state='readonly', readonlybackground ="white")
entries.grid(row =7+i, column =3)
self.akt_b.append(akt_b)
so now 所以现在
for i in range(12):
self.akt_b[i].set(round(list_b[i], 2))
works perfect. 完美的作品。
Sometimes brain just seems to stop... 有时大脑似乎停滞不前...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.