1

All, this is the first time that I post question on StackOverflow.

I am writing a Tkinter application that allows user to enter stock information, and the window looks like this upon start up.

Label1  Label2  Label3
Entry1  Entry2  Entry3

If you want to add one more record, you could click a button and the window now becomes this:

Label1  Label2  Label3
Entry1  Entry2  Entry3
Entry4  Entry5  Entry6

Since I also wanted a button to delete row of record if not needed anymore, I use a piece of code from StackOverflow to append frame one after another.

Here is my question: After the user enter all necessary information and now want to perform calculation, I would like to transfer the entry1, entry2, entry3... into a data frame (or dict, or list) for storage. How could I refer to those Entry, by position, or other method?

The following code is used to add a line (Frame) or record upon each click of the add record button:

self.framelist = []
self.framelist.append(Frame(frame))
self.framelist[-1].grid(row=self.i) #-1 is used to refer to the most recent 
                                    # element

entry1 = Entry(self.framelist[-1])
entry2 = Entry(self.framelist[-1])
entry3 = Entry(self.framelist[-1])
entry1.grid(row=self.i, column=1)    #self.i is just the arbitrary row number
entry2.grid(row=self.i, column=2)
entry3.grid(row=self.i, column=3)

I see the framelist has the type list and is the aggregation of Frame. Is there a way I could reference and retreat the value, for example, the first entry of the second frame?

martineau
  • 119,623
  • 25
  • 170
  • 301
AlexZZZ
  • 11
  • 1
  • 4
    You are already gathering multiple widgets into a list with the code `framelist`. Use a similar strategy for the `Entry` widgets. – TigerhawkT3 Apr 20 '19 at 23:26
  • *"reference ... the value, ... first entry ... second frame?"*: `self.framelist[1].grid_slaves()[0].get()` – stovfl Apr 21 '19 at 10:25
  • @stovfl, you precisely solved my problem. This is exactly what I need!!! Thank you very much!!! – AlexZZZ Apr 22 '19 at 16:50

0 Answers0