我使用PyQt4模块创建用户界面。这个问题我'面对的是,我不能够访问“self.ftp_tableWidget”变量我无法访问我的课程的属性?
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()
这其中ftp_tableWidget被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()
这是更新表小部件的代码。
def adding(self):
self.msg=add_to()
self.msg.show()
这段代码正在调用一个将数据添加到数据库的类。
class add_to(QtGui.QDialog,Ui_MainWindow):
def __init__(self):
super(add_to,self).__init__()
Ui_MainWindow.__init__(self)
这段代码是初始化其数据追加到数据库并调用update_table函数来更新表插件的类。
这是即时得到
self.ftp_tableWidget.setRowCount(count)
AttributeError: 'add_to' object has no attribute 'ftp_tableWidget'
规格的错误: IM使用python 2.7和PyQt4的模块。
根据由 “notbad JPEG” 中给出的的answere编辑代码之后: 类Ui_MainWindow(对象): DEF 初始化(个体,主窗口): self.setupUi(主窗口) DEF setupUi(个体,主窗口):
这是给我一个问题:
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)
这给出了一个错误:
MainWindow.setObjectName(_fromUtf8("MainWindow"))
AttributeError: 'Ui_MainWindow' object has no attribute 'setObjectName'
请问谁能帮我。
Thanx提前
是否存在'Ui_MainWindow。__init __()'调用'setupUi()'? Blkknght:不,它不,Thanx注意。 – Blckknght
我改了一下代码,现在我的Ui_MainWindow – TheCreator232
@ thecreator232上有一个__init__,你能更新代码来反映你的改变吗? – Andy