Get multiple Entry Python values

Asked

Viewed 250 times

-1

The idea is that the user type the number of lines and I create the entry according to this amount, this I managed to do, what I’m not getting is to get 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)        
  • I suggest you create a Minimum, complete and verifiable example of the problem, so it is easy to reproduce and test it. Still I don’t see any get in the code you have in question. Not to mention that all Entry are being kept on top of each other

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 StringVars to get the text of each entry:

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

If all you want is to take the value of Entrys, you don’t even need to store a reference to the entry, only the StringVar are sufficient to take the values after.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.