I'm trying to create a widget that contains an amount of entry fields based on the an aspect of a file that's loaded in.
I've been using
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 on this command. Each entry variable should have a different name so I can call each individual cell, which I don't know if that is possible.
More generally, what I'm trying to do is create a n by 1 table where the user can input an integer to the cells and I can access that value in another function.
More generally, what I'm trying to do is create a n by 1 table...
Use a list
and append however many Entry
widgets are needed.
Each entry variable should have a different name so I can call each individual cell
Simply index the list (of course you could set it up to create new instance variables but you probably don't actually want that).
You can even put your setup code in a function and call that each 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 need 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: Don't use semicolons ;
at the end of each line in Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With