I am reading a csv file and according to the number of rows in the csv, I have created that many number of check boxes. There is a submit button on the screen and after clicking that I want to check which all check boxes have been ticked but right now it is checking whether the box is ticked at the time of check box creation.
I have created the check boxes using a for loop and because of this, I don't have the name of each individual check box and hence the only way I can check if the check box is ticked is by running the .isChecked() function in the for loop. Hence it is checking the check boxes when the for loop runs.
opened csv and counted the no. of rows#### appended the value of the row we want into list 'a' with open("fike_path") as f:
reader = csv.reader(f, delimiter=",")
next(reader)
for i in reader:
a.append(i[4])
print(a)
j=0
created check boxes acc. to no. of rows
for i in range(len(a)):
cb = QCheckBox(a[i], self)
cb.toggle()
cb.resize(200,28)
cb.setChecked(False)
cb.move(720,135+j)
j=j+15
if cb.isChecked() == False: ####checking if check box is ticked####
print (cb.text()+" is not selected")
else:
print("Is selected")
Expected result: print("is selected") for the check boxes which have been ticked and print("is not selected") along with check box value for the boxes which have not been ticked.
Actual result: print("is not selected") for all check boxes as it checks when the for loop is run i.e. the time of creation where default value is false.