The problem is that on each run through the values of self.createShotBtn
, self.labelName
and self.shotName
are being overridden.
So on the last run through, they are fixed, but only for the last iteration.
Instead, you want to use a locally scoped variable in the loop, and potentially store it in an array for later use.
This code should come close to what you need, but I can see where self.shotNumberLst
(which returns a number?) and shotjump
(which is an offest, or equal to to i
) are declared.
self.shots = []
for i in range(seqNum): # Changed while to for, so you don't need to increment
#create each widget
createShotBtn = QtGui.QPushButton("Create Shot %s!" %str(self.shotNumberLst[i-1]))
labelName = QtGui.QLabel(self)
labelName.setText("Enter Name Of Shot %s!" %str(self.shotNumberLst[i-1]))
shotName = QtGui.QLineEdit(self)
self.shots.append({"button":createShotBtn,
"name":shotName)) # Store for later if needed.
#add widget to layout
self.grid.addWidget(labelName, 11+shotjump,0)
self.grid.addWidget(shotName,11+shotjump,1)
self.grid.addWidget(createShotBtn, 11+shotjump,2)
#Press button that makes magic happen
createShotBtn.clicked.connect(self.createShot(i))
#elsewhere
def createShot(self,index):
print self.shots[index]["name"].text