I'm creating a User Interface using PyQt4 module . the problem i'am facing is that i'm not able to access "self.ftp_tableWidget" variable
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(790, 610)
self.FTP = QtGui.QWidget()
self.FTP.setObjectName(_fromUtf8("FTP"))
self.ftp_tableWidget = QtGui.QTableWidget(self.FTP)
self.ftp_tableWidget.setGeometry(QtCore.QRect(40, 90, 411, 192))
self.ftp_tableWidget.setMinimumSize(QtCore.QSize(331, 0))
self.ftp_tableWidget.setObjectName(_fromUtf8("ftp_tableWidget"))
self.ftp_tableWidget.setColumnCount(2)
self.ftp_tableWidget.setRowCount(31)
item = QtGui.QTableWidgetItem()
self.ftp_tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.ftp_tableWidget.setHorizontalHeaderItem(1, item)
self.update_table()
This where the ftp_tableWidget is intialized.
def update_table(self):
cursor.execute('''SELECT MAX(SNO) FROM ftp_auth_table1''')
entry=cursor.fetchall()
entry=entry[0]
count=entry[0]
self.ftp_tableWidget.setRowCount(count)
cursor.execute('''SELECT * FROM ftp_auth_table1''')
entry=cursor.fetchall()
This is the code that updates the table widget.
def adding(self):
self.msg=add_to()
self.msg.show()
This piece of code is calling a class which adds data to the database.
class add_to(QtGui.QDialog,Ui_MainWindow):
def __init__(self):
super(add_to,self).__init__()
Ui_MainWindow.__init__(self)
This piece of code is initializes the class which appends data to the database and calls the update_table function to update the table widget .
This the Error that im getting
self.ftp_tableWidget.setRowCount(count)
AttributeError: 'add_to' object has no attribute 'ftp_tableWidget'
specs : im using python 2.7 and PyQt4 module .
after editing the code according to the answere given by "notbad jpeg": class Ui_MainWindow(object): def init(self,mainwindow): self.setupUi(mainwindow) def setupUi(self, MainWindow):
this is giving me a problem :
class add_to(QtGui.QDialog,Ui_MainWindow):
def __init__(self):
super(add_to,self).__init__()
self.window=QtGui.QMainWindow()
self.MainWindow=Ui_MainWindow(self.window)
Ui_MainWindow.__init__(self,self.MainWindow)
this gives an error:
MainWindow.setObjectName(_fromUtf8("MainWindow"))
AttributeError: 'Ui_MainWindow' object has no attribute 'setObjectName'
Pls can anyone help Me .
Thanx in advance
Ui_MainWindow.__init__()
callsetupUi()
? – Blckknght