很抱歉,我认为这是一个菜鸟问题。这似乎应该很简单。我试图从循环生成的输入框创建列表。
我有两个列表,一个列表“ myLabelList”具有诸如“作业名称,项目名称”等信息,另一个空列表“ myEntryLists”用于从条目中捕获信息。
问题是,当我print(myEntryList)
似乎显示有关条目的信息而不是输入本身时。我有一个解决方法,但这就是事实。
对不起,如果我格式化不好,这是我的第一篇文章。
from tkinter import *
root = Tk()
root.title("Job Information Entry")
root.geometry("400x150")
topFrame = Frame(root)
bottomFrame = Frame(root)
topFrame.grid(row=0, column=0)
bottomFrame.grid(row=1, column=0)
myLabelList = ["Enter Job Number", "Enter Project Name", "Enter Job Name", "Enter Drawing Number"]
myEntryList = []
lst = []
# this is where i seem to be having problems
def ok_button_click():
for entry in myEntryList: # this is my workaround
lst.append(entry.get()) # this is my workaround
print(myEntryList) # this is what im getting
print(lst) # this is what i want to print()
x = 0
for i in myLabelList:
myLabel = Label(topFrame, text=i)
myEntry = Entry(topFrame, width=50)
myLabel.grid(row=x, sticky=E)
myEntry.grid(row=x, column=1)
x = x + 1
myEntryList.append(myEntry)
# bottomFrame
okButton = Button(bottomFrame, text="OK", command=ok_button_click)
cancelButton = Button(bottomFrame, text="Cancel")
okButton.grid(row=0, column=0)
cancelButton.grid(row=0, column=1)
root.mainloop()
在此行中,将Entry
小部件插入myEntryList
: