Sep-29-2017, 05:48 PM
Why would any of those work? None were defined as variables, and python, being a sane language developed for people who are not insane, does not define variables for you unless you do it yourself :p
You'd access them just as you would the elements of any list: through an index.
You'd access them just as you would the elements of any list: through an index.
>>> import tkinter as tk >>> root = tk.Tk() >>> categories = [] >>> for i in range(5): ... cat = tk.StringVar() ... cat.set("test: {0}".format(i)) ... entry = tk.Entry(root, textvariable=cat) ... entry.pack() ... categories.append(cat) ... >>> categories [<tkinter.StringVar object at 0x001B7DB0>, <tkinter.StringVar object at 0x01632AD0>, <tkinter.StringVar object at 0x001EE710>, <tkinter.StringVar object at 0x001EE790>, <tkinter.StringVar object at 0x001EE810>] # at this point, the window has 5 entry fields. I changed the contents of the second to say "spam" # here's how we'd retrieve it's contents later... >>> categories[1].get() 'spam'