我似乎无法从Entry框循环创建的列表中返回特定值。

时间:2018-02-27 05:28:18

标签: python list loops tkinter tkinter-entry

我似乎无法使用函数addDetails返回列表newDetails中的特定项,该列是通过附加我从循环创建的输入框中的输入而创建的。请帮忙。

     import tkinter as tk
     from tkinter import*
     from tkinter import ttk
     import csv

     win = tk.Tk()
     win.title("RFBM Scaffolding Dashboard")
     win.configure(background="grey30")

     newDetails = []
     contactInfo = ["Customer Name", "Home Number", "Mobile Number"] 


     contactInfoFrame = ttk.LabelFrame(win, text ='Contact Information')
     contactInfoFrame.grid(column=0,row=1, columnspan=2)

     for row in range(len(contactInfo)):
         curLabel = contactInfo[row]
         curLabel = ttk.Label(contactInfoFrame, text=contactInfo[row]+":")
         curLabel.grid(column=0, row=(row), sticky=tk.W)

for i in range(len(contactInfo)):
     details = Entry(contactInfoFrame)
     details.grid(row=i, column=1)
     newDetails.append(details)

 def addDetails():
     print(newDetails[1])

  button=Button(win,text="Add Details",command=addDetails).grid(row=12,column=0)


  win.mainloop()

1 个答案:

答案 0 :(得分:1)

print(newDetails[1])返回str对象Entry表示为预期。如果需要获得Entry的输入,则可以使用get方法:

def addDetails():
    print(newDetails[1].get())