Get value from several Entry Python

-1

The idea is that the user type the number of rows and I create the entries according to this amount, this I was able to do, what I can not get is the value of these entry with get ().

        y1=0
        lista= []
        while y1 < x1:
            y1= y1+1             

            lista.append(y1)              


            for y1 in lista:
                self.num= Label(self.root, text= y1,font= fonte, bg=cor).grid(row=(9+y1), column=0,sticky= NW)
                self.cxx = Entry(self.root)
                self.cxx["width"] = 4
                self.cxx["font"] = fonte
                self.cxx.grid(row=(9+y1), column=1)        
    
asked by anonymous 21.07.2018 / 23:06

1 answer

0

For this you have to create several StringVar , one for each entry:

self.entry_vars = [] # lista com todas as StringVars
for y1 in lista:
    sv = StringVar()           # cria uma StringVar e armazena
    self.entry_vars.append(sv) # na lista para uso posterior
    cx = Entry(self.root, textvariable=sv)
    cx["width"] = 4
    cx["font"] = fonte
    cx.grid(row=(9+y1), column=1)

Then just use this list of StringVar s to get the text of each entry:

x = self.entry_vars[2].get() # valor da terceira entry

If all you want is to get the value of Entry s, you do not even need to store a reference to entry, only StringVar is sufficient to get the values later.

    
23.07.2018 / 17:02