所以我用Python和PyQt4创建了一个Windows应用程序。我使用Python 2.7.6。文件ui转换我使用pyuic4 form_window.ui -o form_window.py
from PyQt4 import QtCore, QtGui
import sys
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(QtGui.QMainWindowWidget):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(623, 359)
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.textEdit = QtGui.QTextEdit(self.centralWidget)
self.textEdit.setGeometry(QtCore.QRect(230, 40, 371, 281))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.lineEdit = QtGui.QLineEdit(self.centralWidget)
self.lineEdit.setGeometry(QtCore.QRect(10, 40, 191, 23))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.lineEdit_2 = QtGui.QLineEdit(self.centralWidget)
self.lineEdit_2.setGeometry(QtCore.QRect(10, 80, 191, 23))
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
self.lineEdit_3 = QtGui.QLineEdit(self.centralWidget)
self.lineEdit_3.setGeometry(QtCore.QRect(10, 120, 191, 23))
self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
self.label = QtGui.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(240, 20, 59, 15))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(self.centralWidget)
self.label_2.setGeometry(QtCore.QRect(10, 20, 59, 15))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(self.centralWidget)
self.label_3.setGeometry(QtCore.QRect(10, 60, 59, 21))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.label_4 = QtGui.QLabel(self.centralWidget)
self.label_4.setGeometry(QtCore.QRect(10, 100, 111, 21))
self.label_4.setObjectName(_fromUtf8("label_4"))
self.zapisz_btm = QtGui.QPushButton(self.centralWidget)
self.zapisz_btm.setGeometry(QtCore.QRect(20, 270, 80, 23))
self.zapisz_btm.setObjectName(_fromUtf8("zapisz_btm"))
MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtGui.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 623, 20))
self.menuBar.setObjectName(_fromUtf8("menuBar"))
self.menuForm = QtGui.QMenu(self.menuBar)
self.menuForm.setObjectName(_fromUtf8("menuForm"))
MainWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtGui.QToolBar(MainWindow)
self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtGui.QStatusBar(MainWindow)
self.statusBar.setObjectName(_fromUtf8("statusBar"))
MainWindow.setStatusBar(self.statusBar)
self.menuBar.addAction(self.menuForm.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label.setText(_translate("MainWindow", "Opis", None))
self.label_2.setText(_translate("MainWindow", "Adres", None))
self.label_3.setText(_translate("MainWindow", "Tytul", None))
self.label_4.setText(_translate("MainWindow", "Slowa kluczowe", None))
self.zapisz_btm.setText(_translate("MainWindow", "Zapisz", None))
self.menuForm.setTitle(_translate("MainWindow", "Form", None))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_MainWindow()
ex.show()
sys.exit(app.exec_())
当我运行我的代码时,我有错误
Traceback (most recent call last):
File "/home/develop/PycharmProjects/untitled/form_window.py", line 18, in <module>
class Ui_MainWindow(QtGui.QMainWindowWidget):
AttributeError: 'module' object has no attribute 'QMainWindowWidget'
我不知道我做错了什么
答案 0 :(得分:2)
我在api中看不到课程QMainWindowWidget
:http://pyqt.sourceforge.net/Docs/PyQt4/qtgui.html
您确定不想继承QMainWindow
吗?