Variable Number of input fields in Tkinter

I am trying to create a widget that contains a number of input fields based on the aspect of the downloaded file.

I used

self.e = Entry(self.master); self.e.pack(); self.e.delete(0,END); self.e.insert(0, 0); 

to create each entry, but ideally want to iterate over this command. Each record variable must have a different name, so I can call every single cell that I don't know if it's possible.

More generally, I am trying to create a table n by 1, where the user can enter an integer in the cells, and I can access this value in another function.

+4
source share
1 answer

More generally, I am trying to create a table n by 1 ...

Use list and add, however, more Entry widgets are required.

Each record variable must have a different name, so I can call each individual cell

Just index the list (of course, you can configure it to create new instance variables, but you probably don't want this).

You can even put your installation code in a function and call it every time.

 def create_entry_widget(self, x): new_widget = Entry(self.master) new_widget.pack() new_widget.insert(0, x) return new_widget 

All you have to do is define self.n based on your file.

 self.entry_widgets = [self.create_entry_widget(x) for x in xrange(self.n)] 

NOTE. Do not use semicolons ; at the end of each line in Python.

+3
source

Source: https://habr.com/ru/post/1486302/


All Articles