我似乎无法使用函数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()
答案 0 :(得分:1)
print(newDetails[1])
返回str
对象的Entry
表示为预期。如果需要获得Entry
的输入,则可以使用get
方法:
def addDetails():
print(newDetails[1].get())