Say I have a dictionary full of parameters:
{speed = 1, intelligence = 3, dexterity = 2}
I want to call a loop that creates a Label and a SpinBox for each item in this list procedurally, in case I want to add more attributes later. I can create the window and return the updated values just fine. My only issue is that I want all the widgets to be created as necessary, whether I have 7 or 20 attributes to edit.
So the label object could be called speed_Label and the intelligence label object intelligence_Label, and the spinbox containing the value of speed would be speed_SpinBox and so on, which then I could pass back easily. However, this
a) seems like poor naming practice
b) seems difficult seeing as I can’t find out how to give objects names procedurally, say
for KEY in dict.keys(): # say the KEY is "Speed"
# this would produce a Label object called Speed_Label
# which displays the text "Speed"
"KEY" + "_Label" = QLabel("KEY")
Why not simply use a list or dict?
Something like this should work: