本文介绍了我似乎无法从Entry Box循环创建的列表中返回特定值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法获得addDetails函数来返回newDetails列表中的特定项目,该列表是通过添加从循环创建的输入框的输入而创建的.请帮忙.
I can't seem to get the function addDetails to return a specific item in list newDetails that is created from appending the inputs from entry boxes I created from a loop. Please help.
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()
推荐答案
print(newDetails[1])
按预期返回Entry
对象的str
表示形式.如果需要获取Entry
的输入,请 get
方法可以代替:
print(newDetails[1])
returns str
representation of an Entry
object as expected. If one needs to get the input of an Entry
, get
method can be used instead:
def addDetails():
print(newDetails[1].get())
这篇关于我似乎无法从Entry Box循环创建的列表中返回特定值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!