gpt4 book ai didi

Python/Tkinter。将所有条目存储在列表中的按钮

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:15 28 4
gpt4 key购买 nike

我想创建一个函数(我在下面将其称为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()

谢谢!

最佳答案

这应该可以做到:

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()

当您按下按钮时,条目中的所有内容都会收集到一个列表中,然后在终端中打印。然后窗口关闭。

关于Python/Tkinter。将所有条目存储在列表中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17821074/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com