I Can't Seem To Return A Specific Value From A List Created By A Loop Of Entry Boxes.
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 he
Solution 1:
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())
Solution 2:
You can run this for getting desired output
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, textvariable = newDetails)
details.grid(row=i, column=1)
newDetails.append(details)
def addDetails():
for i in range(len(newDetails)):
print(newDetails[i].get())
button=Button(win,text="Add Details",command=addDetails).grid(row=12,column=0)
win.mainloop()
Post a Comment for "I Can't Seem To Return A Specific Value From A List Created By A Loop Of Entry Boxes."