I used pyuic to compile a GUI file from Qt Designer, and I tried to figure out how to set all the cells in the first column with the same value "n"
.
The following is my code:
class Ui_MainWindow(object):
...
def accinit(self):
for n in xrange(9):
item = self.tableWidget.item(n, 0)
item.setText(_translate("MainWindow", "n", None))
Console ouput:
AttributeError: 'NoneType' object has no attribute 'setText'
I changed the code for only one cell (0,0), and it works perfectly:
def accinit(self):
item = self.tableWidget.item(0, 0)
item.setText(_translate("MainWindow", "n", None))
The cell at (0,0) has content "n"
.
I thought maybe that it's not allowed in a for loop, so I changed code to:
def accinit(self):
for x in xrange(1):
item = self.tableWidget.item(0, 0)
item.setText(_translate("MainWindow", "n", None))
But it still works! Why?
I already referenced the following articles (but I still can't solve this error):
Python: Attribute Error - 'NoneType' object has no attribute 'something'
Python AttributeError: NoneType object has no attribute 'close'