我创建了一个要求输入的弹出窗口,条目数量取决于给出的信息。
self.e = Entry(self.top, bd = 5)
self.e.grid(column = 1, row = 0)
row = 2
for d in extra:
self.e2 = Entry(self.top, bd = 5)
self.e2.grid(column = 1, row = row)
row = row + 1
def ok(self):
new = self.e.get().strip()
函数ok将被一个按钮调用,然后它将返回值。如何从未知数量的条目中返回值列表?
Python 2.7
答案 0 :(得分:2)
通常,您可以将条目放在列表中:
from Tkinter import *
class App(object):
def __init__(self, top):
self.top = top
self.ok_button = Button(self.top, text='OK', command=self.ok)
self.make_entries()
def make_entries(self):
self.entries = []
for d in extra:
e2 = Entry(self.top, bd = 5)
e2.grid(column = 1, row = row)
self.entries.append(e2)
row += 1
def ok(self):
values = [e.get().strip() for e in self.entries]
root = Tk()
app = App(root)
root.mainloop()