我想创建一个关闭窗口的函数(我在下面调用它super_function
),记录在不同Entry
中写入的所有信息并将其存储在列表中。
这是我目前的代码:
from Tkinter import *
def super_function():
# super_function that should store Entry info
# in a list and close the window
fen1 = Tk()
entr = []
for i in range(10):
entr.append(Entry(fen1))
entr[i].grid(row=i+1)
Button(fen1, text = 'store everything in a list', command = fen1.quit).grid()
fen1.mainloop()
谢谢!
答案 0 :(得分:1)
这应该这样做:
from Tkinter import *
def super_function():
out = map(Entry.get, entr)
fen1.destroy()
print out
fen1 = Tk()
entr = []
for i in xrange(10):
entr.append(Entry(fen1))
entr[i].grid(row=i+1)
Button(fen1, text = 'store everything in a list', command = super_function).grid()
fen1.mainloop()
当您按下按钮时,条目中的所有内容都会收集到一个列表中,然后在终端中打印。然后窗口关闭。