简体   繁体   中英

Pyqt5 Ui file converted to python doesnt seem to work

I've used Pyuic5.exe with the command

pyuic5.exe -x filename.ui -o pythonfilename.py

and so this is what it puts in the python file but this doesnt work when i run it in python3 even though i have the -x to make it executable.

this is what it puts into the python file

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '.\untitled.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(500, 400)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
        Dialog.setSizePolicy(sizePolicy)
        Dialog.setSizeIncrement(QtCore.QSize(-23422, 0))
        Dialog.setStyleSheet("qdarkstyle.load_stylesheet()")
        self.Button1 = QtWidgets.QPushButton(Dialog)
        self.Button1.setGeometry(QtCore.QRect(60, 240, 91, 31))
        self.Button1.setMinimumSize(QtCore.QSize(91, 31))
        self.Button1.setObjectName("Button1")
        self.Button2 = QtWidgets.QPushButton(Dialog)
        self.Button2.setGeometry(QtCore.QRect(290, 240, 91, 31))
        self.Button2.setMinimumSize(QtCore.QSize(91, 31))
        self.Button2.setBaseSize(QtCore.QSize(250, 240))
        self.Button2.setObjectName("Button2")
        self.Button3 = QtWidgets.QPushButton(Dialog)
        self.Button3.setGeometry(QtCore.QRect(290, 310, 91, 31))
        self.Button3.setMinimumSize(QtCore.QSize(91, 31))
        self.Button3.setObjectName("Button3")
        self.Button4 = QtWidgets.QPushButton(Dialog)
        self.Button4.setGeometry(QtCore.QRect(60, 310, 91, 31))
        self.Button4.setMinimumSize(QtCore.QSize(91, 31))
        self.Button4.setObjectName("Button4")
        self.Question = QtWidgets.QLabel(Dialog)
        self.Question.setGeometry(QtCore.QRect(70, 40, 301, 61))
        font = QtGui.QFont()
        font.setPointSize(32)
        self.Question.setFont(font)
        self.Question.setObjectName("Question")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.Button1.setText(_translate("Dialog", "PushButton"))
        self.Button2.setText(_translate("Dialog", "PushButton"))
        self.Button3.setText(_translate("Dialog", "PushButton"))
        self.Button4.setText(_translate("Dialog", "PushButton"))
        self.Question.setText(_translate("Dialog", "TextLabel"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

It's probably missing app or show somewhere...

convert to executable python file -

pyuic5 -x -o pythonfilename.py filename.ui

convert qrc to python file :

pyrcc5 -o pyfilename.py res.qrc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM