PyQt4表单未启动

时间:2016-05-11 17:01:42

标签: python pyqt python-3.4 qt-designer

我已经制作了以下代码来执行在QtDesigner中制作的表格并转换为'.py'文件。我的问题是,当我执行代码时,它并没有真正显示表单,但没有消息错误,它在工具栏上显示一个python图标,如果它正在运行表单,我尝试从cmd启动它。 exe,但同样的事情发生.PD:我使用Sublime Text 3和Python 3.4.4。请帮忙,谢谢!

from PyQt4 import QtGui
import sys
import form3qt_edit

class Form3(QtGui.QMainWindow, form3qt_edit.Ui_MainWindow):
    def __init__(self,parent =None):
        super(Form3, self).__init__(parent)
        self.setupUi(self)

def main():
    app = QtGui.QApplication(sys.argv)
    form = Form3()
    form.show()
    app.exec_()

if __name__ == '__main__':
    main()

formqt3_edit.py的代码

from PyQt4 import QtCore, QtGui

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(710, 450)
        MainWindow.setWindowOpacity(-1.0)
        MainWindow.setStyleSheet(_fromUtf8("background-color:\'#effec7\';\n"
"border-radius:20px;\n"
"\n"
""))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setGeometry(QtCore.QRect(150, 90, 391, 261))
        self.tabWidget.setStyleSheet(_fromUtf8("background-color:\'#effec7\';\n"
"background-color: rgb(211, 207, 157);"))
        self.tabWidget.setTabPosition(QtGui.QTabWidget.North)
        self.tabWidget.setTabShape(QtGui.QTabWidget.Rounded)
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tP = QtGui.QWidget()
        self.tP.setObjectName(_fromUtf8("tP"))
        self.checkBox = QtGui.QCheckBox(self.tP)
        self.checkBox.setGeometry(QtCore.QRect(20, 10, 151, 17))
        self.checkBox.setObjectName(_fromUtf8("checkBox"))
        self.checkBox_2 = QtGui.QCheckBox(self.tP)
        self.checkBox_2.setGeometry(QtCore.QRect(20, 40, 141, 17))
        self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
        self.checkBox_3 = QtGui.QCheckBox(self.tP)
        self.checkBox_3.setGeometry(QtCore.QRect(20, 70, 141, 17))
        self.checkBox_3.setObjectName(_fromUtf8("checkBox_3"))
        self.tabWidget.addTab(self.tP, _fromUtf8(""))
        self.tC = QtGui.QWidget()
        self.tC.setObjectName(_fromUtf8("tC"))
        self.checkBox_4 = QtGui.QCheckBox(self.tC)
        self.checkBox_4.setGeometry(QtCore.QRect(20, 10, 141, 17))
        self.checkBox_4.setObjectName(_fromUtf8("checkBox_4"))
        self.checkBox_5 = QtGui.QCheckBox(self.tC)
        self.checkBox_5.setGeometry(QtCore.QRect(20, 30, 171, 17))
        self.checkBox_5.setObjectName(_fromUtf8("checkBox_5"))
        self.checkBox_6 = QtGui.QCheckBox(self.tC)
        self.checkBox_6.setGeometry(QtCore.QRect(20, 50, 261, 17))
        self.checkBox_6.setObjectName(_fromUtf8("checkBox_6"))
        self.checkBox_7 = QtGui.QCheckBox(self.tC)
        self.checkBox_7.setGeometry(QtCore.QRect(20, 70, 151, 17))
        self.checkBox_7.setObjectName(_fromUtf8("checkBox_7"))
        self.checkBox_8 = QtGui.QCheckBox(self.tC)
        self.checkBox_8.setGeometry(QtCore.QRect(20, 90, 331, 17))
        self.checkBox_8.setObjectName(_fromUtf8("checkBox_8"))
        self.checkBox_9 = QtGui.QCheckBox(self.tC)
        self.checkBox_9.setGeometry(QtCore.QRect(20, 110, 251, 17))
        self.checkBox_9.setObjectName(_fromUtf8("checkBox_9"))
        self.checkBox_10 = QtGui.QCheckBox(self.tC)
        self.checkBox_10.setGeometry(QtCore.QRect(20, 130, 191, 17))
        self.checkBox_10.setObjectName(_fromUtf8("checkBox_10"))
        self.checkBox_11 = QtGui.QCheckBox(self.tC)
        self.checkBox_11.setGeometry(QtCore.QRect(20, 150, 331, 17))
        self.checkBox_11.setObjectName(_fromUtf8("checkBox_11"))
        self.checkBox_12 = QtGui.QCheckBox(self.tC)
        self.checkBox_12.setGeometry(QtCore.QRect(20, 170, 231, 17))
        self.checkBox_12.setObjectName(_fromUtf8("checkBox_12"))
        self.checkBox_13 = QtGui.QCheckBox(self.tC)
        self.checkBox_13.setGeometry(QtCore.QRect(20, 190, 201, 17))
        self.checkBox_13.setObjectName(_fromUtf8("checkBox_13"))
        self.checkBox_14 = QtGui.QCheckBox(self.tC)
        self.checkBox_14.setGeometry(QtCore.QRect(20, 210, 231, 17))
        self.checkBox_14.setObjectName(_fromUtf8("checkBox_14"))
        self.tabWidget.addTab(self.tC, _fromUtf8(""))
        self.tO = QtGui.QWidget()
        self.tO.setObjectName(_fromUtf8("tO"))
        self.checkBox_15 = QtGui.QCheckBox(self.tO)
        self.checkBox_15.setGeometry(QtCore.QRect(20, 10, 141, 17))
        self.checkBox_15.setObjectName(_fromUtf8("checkBox_15"))
        self.checkBox_16 = QtGui.QCheckBox(self.tO)
        self.checkBox_16.setGeometry(QtCore.QRect(20, 30, 201, 17))
        self.checkBox_16.setObjectName(_fromUtf8("checkBox_16"))
        self.checkBox_17 = QtGui.QCheckBox(self.tO)
        self.checkBox_17.setGeometry(QtCore.QRect(20, 50, 201, 17))
        self.checkBox_17.setObjectName(_fromUtf8("checkBox_17"))
        self.checkBox_18 = QtGui.QCheckBox(self.tO)
        self.checkBox_18.setGeometry(QtCore.QRect(20, 70, 191, 17))
        self.checkBox_18.setObjectName(_fromUtf8("checkBox_18"))
        self.checkBox_19 = QtGui.QCheckBox(self.tO)
        self.checkBox_19.setGeometry(QtCore.QRect(20, 90, 221, 17))
        self.checkBox_19.setObjectName(_fromUtf8("checkBox_19"))
        self.checkBox_20 = QtGui.QCheckBox(self.tO)
        self.checkBox_20.setGeometry(QtCore.QRect(20, 110, 161, 17))
        self.checkBox_20.setObjectName(_fromUtf8("checkBox_20"))
        self.checkBox_21 = QtGui.QCheckBox(self.tO)
        self.checkBox_21.setGeometry(QtCore.QRect(20, 130, 271, 17))
        self.checkBox_21.setObjectName(_fromUtf8("checkBox_21"))
        self.checkBox_22 = QtGui.QCheckBox(self.tO)
        self.checkBox_22.setGeometry(QtCore.QRect(20, 150, 201, 17))
        self.checkBox_22.setObjectName(_fromUtf8("checkBox_22"))
        self.checkBox_23 = QtGui.QCheckBox(self.tO)
        self.checkBox_23.setGeometry(QtCore.QRect(20, 170, 231, 17))
        self.checkBox_23.setObjectName(_fromUtf8("checkBox_23"))
        self.tabWidget.addTab(self.tO, _fromUtf8(""))
        self.tA = QtGui.QWidget()
        self.tA.setObjectName(_fromUtf8("tA"))
        self.checkBox_24 = QtGui.QCheckBox(self.tA)
        self.checkBox_24.setGeometry(QtCore.QRect(30, 10, 171, 17))
        self.checkBox_24.setObjectName(_fromUtf8("checkBox_24"))
        self.checkBox_25 = QtGui.QCheckBox(self.tA)
        self.checkBox_25.setGeometry(QtCore.QRect(30, 50, 121, 17))
        self.checkBox_25.setObjectName(_fromUtf8("checkBox_25"))
        self.checkBox_26 = QtGui.QCheckBox(self.tA)
        self.checkBox_26.setGeometry(QtCore.QRect(30, 70, 111, 17))
        self.checkBox_26.setObjectName(_fromUtf8("checkBox_26"))
        self.checkBox_27 = QtGui.QCheckBox(self.tA)
        self.checkBox_27.setGeometry(QtCore.QRect(30, 30, 241, 17))
        self.checkBox_27.setObjectName(_fromUtf8("checkBox_27"))
        self.tabWidget.addTab(self.tA, _fromUtf8(""))
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(230, -10, 211, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Yu Gothic UI Semibold"))
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName(_fromUtf8("label"))
        self.plainTextEdit = QtGui.QPlainTextEdit(self.centralwidget)
        self.plainTextEdit.setGeometry(QtCore.QRect(140, 30, 411, 51))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Yu Gothic UI Semibold"))
        self.plainTextEdit.setFont(font)
        self.plainTextEdit.setStyleSheet(_fromUtf8("background-color: \'#effec7\'"))
        self.plainTextEdit.setReadOnly(True)
        self.plainTextEdit.setBackgroundVisible(True)
        self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit"))
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(270, 370, 141, 23))
        self.pushButton.setStyleSheet(_fromUtf8("border-radius:\'20px\';\n"
"background-color:\'#bea575\';\n"
"border-color:\'#e2d2ae\';\n"
""))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 710, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(3)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "Form3-QtDesigner", None))
        self.checkBox.setText(_translate("MainWindow", "Gestión de trámites legales", None))
        self.checkBox_2.setText(_translate("MainWindow", "Realización de línea base y estudios técnicos", None))
        self.checkBox_3.setText(_translate("MainWindow", "Realización de diseños", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tP), _translate("MainWindow", "Planeación", None))
        self.checkBox_4.setText(_translate("MainWindow", "Localización y replanteo", None))
        self.checkBox_5.setText(_translate("MainWindow", "Adecuación de accesos o vías", None))
        self.checkBox_6.setText(_translate("MainWindow", "Instalación de obras provisionales y/o definitivas", None))
        self.checkBox_7.setText(_translate("MainWindow", "Explotación de préstamos", None))
        self.checkBox_8.setText(_translate("MainWindow", "Ejecución de tratamientos silviculturales y manejo de coberturas", None))
        self.checkBox_9.setText(_translate("MainWindow", "Construcción de obras de protección y drenaje", None))
        self.checkBox_10.setText(_translate("MainWindow", "Realización de trabajos preliminares", None))
        self.checkBox_11.setText(_translate("MainWindow", "Ejecución de cimentaciones, fundaciones, relleno y compactación", None))
        self.checkBox_12.setText(_translate("MainWindow", "Levantamiento o instalación de estructuras.", None))
        self.checkBox_13.setText(_translate("MainWindow", "Levantamiento o instalación de muros", None))
        self.checkBox_14.setText(_translate("MainWindow", "Realización de acabados y obras exteriores", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tC), _translate("MainWindow", "Construcción", None))
        self.checkBox_15.setText(_translate("MainWindow", "Realización de pruebas", None))
        self.checkBox_16.setText(_translate("MainWindow", "Operación obra de infraestructura", None))
        self.checkBox_17.setText(_translate("MainWindow", "Reposición de elementos o tramos", None))
        self.checkBox_18.setText(_translate("MainWindow", "Reparación de elementos o tramos", None))
        self.checkBox_19.setText(_translate("MainWindow", "Limpieza de las instalaciones y elementos", None))
        self.checkBox_20.setText(_translate("MainWindow", "Mejoramiento o ampliaciones", None))
        self.checkBox_21.setText(_translate("MainWindow", "Limpieza final de la obra e instalaciones temporales", None))
        self.checkBox_22.setText(_translate("MainWindow", "Control de emisiones y vertimientos", None))
        self.checkBox_23.setText(_translate("MainWindow", "Cobertura o reconformación final del sitio", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tO), _translate("MainWindow", "Operación", None))
        self.checkBox_24.setText(_translate("MainWindow", "Desmantelamiento/demolición", None))
        self.checkBox_25.setText(_translate("MainWindow", "Obras de urbanismo", None))
        self.checkBox_26.setText(_translate("MainWindow", "Uso final del sitio", None))
        self.checkBox_27.setText(_translate("MainWindow", "Reactivación de un servicio o sistema natural", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tA), _translate("MainWindow", "Abandono", None))
        self.label.setText(_translate("MainWindow", "Selección de actividades", None))
        self.plainTextEdit.setPlainText(_translate("MainWindow", "Por favor, seleccione las actividades de ingeniería que se llevarán a cabo en el proyecto, de acuerdo con la fase del ciclo de vida.\n"
"Luego de la selección, haga clik en el botón \"Seleccionar impactos\"", None))
        self.pushButton.setText(_translate("MainWindow", "Seleccionar impactos", None))

1 个答案:

答案 0 :(得分:0)

尝试更改

MainWindow.setWindowOpacity(-1.0)

MainWindow.setWindowOpacity(1.0)

来自http://doc.qt.io/qt-4.8/qwidget.html#windowOpacity-prop 不透明度的有效范围是从1.0(完全不透明)到0.0(完全透明)。

我在使用Python 2.7.11+的Ubuntu上尝试了你的代码并获得了与你相同的结果

  

它并没有真正显示表单,但没有消息错误   在工具栏上显示一个python图标,就好像它正在运行表单

一样

但改变这一行修复了问题

更新:刚刚在Windows 10,Python 3.4.4,PyQt4,Sublime build 3103上尝试过它。它可以使用更新的代码行,甚至可以从Sublime(使用Ctrl + B)开始,只需提供两个文件一个变化。