Python Forum
data from multiple Entry widgets
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
data from multiple Entry widgets
#1
Hi, New python user here.

I have an array of 160 Entry widgets. I created them inside nested for loops, rather than 160 explicit lines. Now, I don't know how to read them. I tried:
(Inside FOR loops)
xxx[a,b,c] = Entry(root, bg="white",fg="black", width=7, relief=SUNKEN).grid(row=p_row,column=p_col+1)
I then tried getting the data like this:
for a in range(8):
          for b in range(4):
            for c in range(5):
               xxx[a,b,c].get()
    print(xxx)
But it doesn't work. Is there a way to do this, or do I have to have 160 lines with 160 separate variables?

Thanks,
Reply
#2
What do you expect line 4 to do? If any data is returned by the get(), it's immediately discarded because you don't assign it to anything. So the sub loops don't do anything useful.
Reply
#3
Get 1 entry to work before you make 160.

This is not going to work the way you want. Why is x None?
xxx = Entry(root).grid(row=0,column=0)
print(x)
Reply
#4
(Aug-15-2020, 07:51 PM)bowlofred Wrote: What do you expect line 4 to do? If any data is returned by the get(), it's immediately discarded because you don't assign it to anything. So the sub loops don't do anything useful.

I EXPECT line 4 to read the data from the associated entry and put it in an array. If a=1 and b=2 and c=3, I expect array element xxx[1,2,3] to be assigned the value from the Entry widget previously assigned in the for loop:
xxx[a,b,c]=Entry(...
Reply
#5
xxx = Entry(root).grid(row=0,column=0)

Entry(root) creates an entry object. What does .grid do? What is returned when you call Entry(root)? What is returned when you call .grid?

Don't EXPECT. VERIFY.
Reply
#6
(Aug-15-2020, 08:52 PM)deanhystad Wrote: xxx = Entry(root).grid(row=0,column=0)

Entry(root) creates an entry object. What does .grid do? What is returned when you call Entry(root)? What is returned when you call .grid?

Don't EXPECT. VERIFY.
Don't lecture me. Your condescending attitude is offensive.

I'm trying to verify it. THAT'S WHY I POSTED THIS!

.grid positions the widget.
Reply
#7
(Aug-15-2020, 08:59 PM)beevee Wrote:
(Aug-15-2020, 08:52 PM)deanhystad Wrote: xxx = Entry(root).grid(row=0,column=0)

Entry(root) creates an entry object. What does .grid do? What is returned when you call Entry(root)? What is returned when you call .grid? When I look at the documentation see that .grid does position the widget and it RETURNS NONE. So you are starting you program by throwing away any handle you have to the Entry objects.

Later on you make another mistake, but you should probably get your list of Entry widgets working first.

Don't EXPECT. VERIFY.
Don't lecture me. Your condescending attitude is offensive.

I'm trying to verify it. THAT'S WHY I POSTED THIS!

.grid positions the widget.

Not lecturing. If you lookup what .grid does you will have the answer to your question.
Reply
#8
(Aug-15-2020, 08:41 PM)beevee Wrote: I EXPECT line 4 to read the data from the associated entry and put it in an array.

I don't know what list/array you want it to be put in. Something like

mylist.append(xxx[a,b,c])
would put the value onto mylist. In the original line, there's no location for the data that you're looking up.
Reply
#9
(Aug-15-2020, 10:02 PM)bowlofred Wrote:
(Aug-15-2020, 08:41 PM)beevee Wrote: I EXPECT line 4 to read the data from the associated entry and put it in an array.

I don't know what list/array you want it to be put in. Something like

mylist.append(xxx[a,b,c])
would put the value onto mylist. In the original line, there's no location for the data that you're looking up.

This is where my confusion is coming from. Let me be more specific:
1) I want to create 160 Entry widgets on the screen
2) I want a function to read the data in those 160 widgets.

The way I understand it, I could create 160 discrete Entry widgets like this:
 e1=Entry(...
e2=Entry(...
e160=Entry(...
Then to read the data I could write:
 xxx[0,0,0]=e1.get()
xxx[0,0,1]=e2.get()
xxx[7,4,3]=e160.get()
Am I correct so far?

So, I want to condense like I could in, say, C, using for loops so that I don't have to write 320 lines.
Reply
#10
The array is not the problem. If you did this
xxx[a,b,c] = Entry(root....)
xxx[a,b,c].grid(...
You would have a list of entry widgets that you could later use like this:
values[a,b,c] = xxx[a,b,c].get()
The problem you were having had to do with not knowing that .grid returns None and not saving the values returned by get(). You would have the same problem if you used independent variables.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Project Structure for Modularity and Reusability with Multiple Entry Points b19wh33l5 0 100 Yesterday, 12:21 PM
Last Post: b19wh33l5
  Load multiple Jason data in one Data Frame vijays3 6 1,555 Aug-12-2022, 05:17 PM
Last Post: vijays3
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,616 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  How to map two data frames based on multiple condition SriRajesh 0 1,487 Oct-27-2021, 02:43 PM
Last Post: SriRajesh
  Load the data from multiple source files to one table amy83 2 2,593 Apr-27-2021, 12:33 AM
Last Post: Pedroski55
  API Gateway to manage multiple API's get put data robsuttonjr 2 2,538 Mar-09-2021, 04:09 PM
Last Post: robsuttonjr
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 6,836 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  How to filter out Column data From Multiple rows data? firaki12345 10 5,126 Feb-06-2021, 04:54 AM
Last Post: buran
  Fetching data from multiple tables in a single request. swaroop 0 1,902 Jan-09-2021, 04:23 PM
Last Post: swaroop
  How to fill parameter with data from multiple columns CSV file greenpine 1 1,665 Dec-21-2020, 06:50 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020