I have a problem with my python code. I am writing a GUI in python using tkinter that displays several blocks with about 10 rows with 4 radiobuttons, an entry field and a scale in each row. Code below
for r,v,mi,ma,i in zip(self.radiobuttonShapes, self.valueShapes, self.minShapes, self.maxShapes, range(1,10)):
ttk.Label(self.Shape, text="Shape " + str(i)).grid(column=0, row=i)
ttk.Radiobutton(self.Shape, text="Off", variable=r, value=1, command=self.resetAllRadiosShape).grid(column=1, row=i)
ttk.Radiobutton(self.Shape, text="Max", variable=r, value=2, command=self.resetAllRadiosShape).grid(column=2, row=i)
ttk.Radiobutton(self.Shape, text="Min", variable=r, value=3, command=self.resetAllRadiosShape).grid(column=3, row=i)
ttk.Radiobutton(self.Shape, text="Approx", variable=r, value=4, command=self.resetAllRadiosShape).grid(column=4, row=i)
ttk.Entry(self.Shape, textvariable=v).grid(column=5, row=i)
ttk.Scale(self.Shape, from_=mi, to=ma, variable=v).grid(column=6, row=i)
This mostly works fine.
My problem arises when i want to add an label to put it all into and expand that label with another row including and entry field and a scale, to use with the approx option.
My problem consists of not being able to create the variables on the fly and be able to access them by their methods afterwards.
Might not be clear to understand, but i think the dummy code below makes it easier. I want to be able to make parts of it inactive (the approx field when approx is not chosen).
for i in 1 2 3 4 5 6 7 8 9
self.outerLabel$(i) = ttk.Label(self.Shape).grid(row=i)
self.upperLabel$(i) = ttk.Label(self.outerLabel$(i)).grid(row=0)
ttk.Radiobutton(self.upperLabel$(i)).grid(column=0)
ttk.Radiobutton(self.upperLabel$(i)).grid(column=1)
ttk.Radiobutton(self.upperLabel$(i)).grid(column=2)
ttk.Radiobutton(self.upperLabel$(i)).grid(column=3)
ttk.Entry(self.upperLabel$(i)).grid(column=4)
ttk.Scale(self.upperLabel$(i)).grid(column=5)
self.lowerLabel$(i) = ttk.Label(self.outerLabel$(i)).grid(row=1)
ttk.Entry(self.lowerLabel$(i)).grid(column=0)
ttk.Scale(self.lowerLabel$(i)).grid(column=1)
self.lowerLabel$(i).configure(state=DISABLED)
You should use a dictionary for this, instead of dynamic variable names, the setup code would look something like this:
And wherever the code is from your question: