1

In its current state I have created two lists, NameValues and AgeValues which contain the values written into a series of generated entry boxes when a button is clicked. I now need to insert them into a sqlite table. Before I can do the query however I am having problems assigning all the values to the variables Name and Age.

My problem is that if there are 2 entry boxes created for each variable and the values are submitted the program will only get the values in the last set of entry boxes, retrieving only half the data.

This is the code to fetch the data:

  NameValues = []
  AgeValues = []

def Insert(self):

    for i in range(len(self.NameValues)):
        Name = (self.NameValues[i].get())

    for i in range(len(self.AgeValues)):
       Age = (self.AgeValues[i].get())

    Code = self.MemberCode.get()

    print (Age)

I am printing the age as a test to see what values are stored in the variables and only the last value is being entered.

1
  • The print statement for age is out of indentation Commented Mar 14, 2018 at 13:16

1 Answer 1

1

You need to have Name & Age as a list. I have used list comprehension to assign all value to Name and Age list.

Ex:

NameValues = []
AgeValues = []

def Insert(self):


    Name = [self.NameValues[i].get() for i in range(len(self.NameValues))]
    Age =[self.AgeValues[i].get() for i in range(len(self.AgeValues))]
    Code = self.MemberCode.get()

    print (Age)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I made the modifications to the code and it printed multiple values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.