我是python 3.3的新手,在随机的简单任务中遇到了一些麻烦。我在qt设计器中做了一个gui并导出了py代码。我添加了
def show(self):
self.QtGui.show()
sys.exit(self.exec_())
和
MainWindow = Ui_MainWindow(sys.argv)
MainWindow.show()
到最后,在我添加所有代码之前尝试查看 GUI。我确定这是可能的,我只是想不通。我的整个代码是:
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(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(390, 355)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 10, 371, 301))
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.TS2 = QtGui.QWidget()
self.TS2.setObjectName(_fromUtf8("TS2"))
self.lineEdit = QtGui.QLineEdit(self.TS2)
self.lineEdit.setGeometry(QtCore.QRect(120, 30, 91, 20))
self.lineEdit.setText(_fromUtf8(""))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.spinBox = QtGui.QSpinBox(self.TS2)
self.spinBox.setGeometry(QtCore.QRect(120, 70, 42, 22))
self.spinBox.setObjectName(_fromUtf8("spinBox"))
self.pushButton = QtGui.QPushButton(self.TS2)
self.pushButton.setGeometry(QtCore.QRect(140, 230, 91, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.label = QtGui.QLabel(self.TS2)
self.label.setGeometry(QtCore.QRect(20, 30, 91, 16))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(self.TS2)
self.label_2.setGeometry(QtCore.QRect(20, 70, 91, 20))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_11 = QtGui.QLabel(self.TS2)
self.label_11.setGeometry(QtCore.QRect(20, 170, 91, 21))
self.label_11.setObjectName(_fromUtf8("label_11"))
self.lineEdit_6 = QtGui.QLineEdit(self.TS2)
self.lineEdit_6.setGeometry(QtCore.QRect(120, 170, 131, 20))
self.lineEdit_6.setObjectName(_fromUtf8("lineEdit_6"))
self.pushButton_6 = QtGui.QPushButton(self.TS2)
self.pushButton_6.setGeometry(QtCore.QRect(260, 170, 75, 23))
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.line_2 = QtGui.QFrame(self.TS2)
self.line_2.setGeometry(QtCore.QRect(0, 200, 371, 20))
self.line_2.setFrameShape(QtGui.QFrame.HLine)
self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
self.line_2.setObjectName(_fromUtf8("line_2"))
self.tabWidget.addTab(self.TS2, _fromUtf8(""))
self.AGS = QtGui.QWidget()
self.AGS.setObjectName(_fromUtf8("AGS"))
self.lineEdit_2 = QtGui.QLineEdit(self.AGS)
self.lineEdit_2.setGeometry(QtCore.QRect(120, 30, 91, 20))
self.lineEdit_2.setText(_fromUtf8(""))
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
self.label_3 = QtGui.QLabel(self.AGS)
self.label_3.setGeometry(QtCore.QRect(20, 30, 91, 16))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.spinBox_2 = QtGui.QSpinBox(self.AGS)
self.spinBox_2.setGeometry(QtCore.QRect(120, 70, 42, 22))
self.spinBox_2.setObjectName(_fromUtf8("spinBox_2"))
self.label_4 = QtGui.QLabel(self.AGS)
self.label_4.setGeometry(QtCore.QRect(20, 70, 91, 20))
self.label_4.setObjectName(_fromUtf8("label_4"))
self.pushButton_2 = QtGui.QPushButton(self.AGS)
self.pushButton_2.setGeometry(QtCore.QRect(140, 230, 91, 23))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.label_8 = QtGui.QLabel(self.AGS)
self.label_8.setGeometry(QtCore.QRect(20, 110, 91, 21))
self.label_8.setObjectName(_fromUtf8("label_8"))
self.label_10 = QtGui.QLabel(self.AGS)
self.label_10.setGeometry(QtCore.QRect(20, 170, 91, 21))
self.label_10.setObjectName(_fromUtf8("label_10"))
self.lineEdit_5 = QtGui.QLineEdit(self.AGS)
self.lineEdit_5.setGeometry(QtCore.QRect(120, 170, 131, 20))
self.lineEdit_5.setObjectName(_fromUtf8("lineEdit_5"))
self.pushButton_5 = QtGui.QPushButton(self.AGS)
self.pushButton_5.setGeometry(QtCore.QRect(260, 170, 75, 23))
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.lineEdit_7 = QtGui.QLineEdit(self.AGS)
self.lineEdit_7.setGeometry(QtCore.QRect(120, 110, 31, 20))
self.lineEdit_7.setObjectName(_fromUtf8("lineEdit_7"))
self.label_12 = QtGui.QLabel(self.AGS)
self.label_12.setGeometry(QtCore.QRect(160, 110, 61, 21))
self.label_12.setObjectName(_fromUtf8("label_12"))
self.line = QtGui.QFrame(self.AGS)
self.line.setGeometry(QtCore.QRect(0, 200, 371, 20))
self.line.setFrameShape(QtGui.QFrame.HLine)
self.line.setFrameShadow(QtGui.QFrame.Sunken)
self.line.setObjectName(_fromUtf8("line"))
self.tabWidget.addTab(self.AGS, _fromUtf8(""))
self.AQT = QtGui.QWidget()
self.AQT.setObjectName(_fromUtf8("AQT"))
self.label_5 = QtGui.QLabel(self.AQT)
self.label_5.setGeometry(QtCore.QRect(20, 30, 91, 16))
self.label_5.setObjectName(_fromUtf8("label_5"))
self.lineEdit_3 = QtGui.QLineEdit(self.AQT)
self.lineEdit_3.setGeometry(QtCore.QRect(120, 30, 91, 20))
self.lineEdit_3.setText(_fromUtf8(""))
self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
self.spinBox_3 = QtGui.QSpinBox(self.AQT)
self.spinBox_3.setGeometry(QtCore.QRect(120, 70, 42, 22))
self.spinBox_3.setObjectName(_fromUtf8("spinBox_3"))
self.label_6 = QtGui.QLabel(self.AQT)
self.label_6.setGeometry(QtCore.QRect(20, 70, 91, 20))
self.label_6.setObjectName(_fromUtf8("label_6"))
self.pushButton_3 = QtGui.QPushButton(self.AQT)
self.pushButton_3.setGeometry(QtCore.QRect(140, 230, 91, 23))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.dateEdit = QtGui.QDateEdit(self.AQT)
self.dateEdit.setGeometry(QtCore.QRect(120, 110, 110, 22))
self.dateEdit.setObjectName(_fromUtf8("dateEdit"))
self.label_7 = QtGui.QLabel(self.AQT)
self.label_7.setGeometry(QtCore.QRect(20, 110, 91, 21))
self.label_7.setObjectName(_fromUtf8("label_7"))
self.pushButton_4 = QtGui.QPushButton(self.AQT)
self.pushButton_4.setGeometry(QtCore.QRect(260, 170, 75, 23))
self.pushButton_4.setFlat(False)
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.lineEdit_4 = QtGui.QLineEdit(self.AQT)
self.lineEdit_4.setGeometry(QtCore.QRect(120, 170, 131, 20))
self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4"))
self.label_9 = QtGui.QLabel(self.AQT)
self.label_9.setGeometry(QtCore.QRect(20, 170, 91, 21))
self.label_9.setObjectName(_fromUtf8("label_9"))
self.line_3 = QtGui.QFrame(self.AQT)
self.line_3.setGeometry(QtCore.QRect(0, 200, 371, 20))
self.line_3.setFrameShape(QtGui.QFrame.HLine)
self.line_3.setFrameShadow(QtGui.QFrame.Sunken)
self.line_3.setObjectName(_fromUtf8("line_3"))
self.tabWidget.addTab(self.AQT, _fromUtf8(""))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 390, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menuFile = QtGui.QMenu(self.menubar)
self.menuFile.setObjectName(_fromUtf8("menuFile"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.actionExit = QtGui.QAction(MainWindow)
self.actionExit.setObjectName(_fromUtf8("actionExit"))
self.menuFile.addAction(self.actionExit)
self.menubar.addAction(self.menuFile.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.pushButton.setText(_translate("MainWindow", "Execute", None))
self.label.setText(_translate("MainWindow", "XXXXXXXXX:", None))
self.label_2.setText(_translate("MainWindow", "xXXXXXXXXXXX:", None))
self.label_11.setText(_translate("MainWindow", "XXXXXXXXXX:", None))
self.pushButton_6.setText(_translate("MainWindow", "Browse", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.TS2), _translate("MainWindow", "XXXXXX", None))
self.label_3.setText(_translate("MainWindow", "XXXXXXXX:", None))
self.label_4.setText(_translate("MainWindow", "XXXXXXXXXXX:", None))
self.pushButton_2.setText(_translate("MainWindow", "Execute", None))
self.label_8.setText(_translate("MainWindow", "xXXXXXXXX:", None))
self.label_10.setText(_translate("MainWindow", "XXXXXXXX:", None))
self.pushButton_5.setText(_translate("MainWindow", "Browse", None))
self.label_12.setText(_translate("MainWindow", "XXXXXX", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.AGS), _translate("MainWindow", "XXXXXX", None))
self.label_5.setText(_translate("MainWindow", "XXXX:", None))
self.label_6.setText(_translate("MainWindow", "XXXXX:", None))
self.pushButton_3.setText(_translate("MainWindow", "Execute", None))
self.dateEdit.setDisplayFormat(_translate("MainWindow", "yyyy-MM-dd", None))
self.label_7.setText(_translate("MainWindow", "XXXXX:", None))
self.pushButton_4.setText(_translate("MainWindow", "Browse", None))
self.label_9.setText(_translate("MainWindow", "xXXXXXX:", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.AQT), _translate("MainWindow", "XXXXX", None))
self.menuFile.setTitle(_translate("MainWindow", "File", None))
self.actionExit.setText(_translate("MainWindow", "Exit", None))
def show(self):
self.QtGui.show()
sys.exit(self.exec_())
MainWindow = Ui_MainWindow(sys.argv)
MainWindow.show()
我得到的错误是:
TypeError: object.__new__() takes no parameters
现在我什至不确定此错误是否与我的问题有关,但我正处于绳索的尽头,试图简单地查看此 UI。尚不需要任何功能。
提前谢谢你!
您不需要手动执行此操作。 pyuic4
有一个选项来添加这个: -x
.然后,您只需运行pyuic4
生成的代码,您将看到小部件。例如:
pyuic4 -x -o output.py input.ui