PyQt5 setupUi () au nevoie de un argument mai pozitional

voturi
0

Am făcut o căutare cu thoses Exemple de „setupUi () lipsește un argument de pozitie“ pe StackOverflow, dar nu am găsit răspunsul la problema mea.

Am făcut designul meu pe Qt Designer și converti la .py cu pyuic5. Iată codul genera:

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

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

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(MainWindow)
        MainWindow.resize(623, 266)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName(centralwidget)
        self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(110, 30, 411, 171))
        self.horizontalLayoutWidget.setObjectName(horizontalLayoutWidget)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_2.setObjectName(horizontalLayout_2)
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName(verticalLayout)
        self.cB_flashMaster = QtWidgets.QCheckBox(self.horizontalLayoutWidget)
        self.cB_flashMaster.setObjectName(cB_flashMaster)
        self.verticalLayout.addWidget(self.cB_flashMaster)
        self.line_4 = QtWidgets.QFrame(self.horizontalLayoutWidget)
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName(line_4)
        self.verticalLayout.addWidget(self.line_4)
        self.cB_genFW = QtWidgets.QCheckBox(self.horizontalLayoutWidget)
        self.cB_genFW.setObjectName(cB_genFW)
        self.verticalLayout.addWidget(self.cB_genFW)
        self.line_3 = QtWidgets.QFrame(self.horizontalLayoutWidget)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName(line_3)
        self.verticalLayout.addWidget(self.line_3)
        self.pB_flash = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.pB_flash.setObjectName(pB_flash)
        self.verticalLayout.addWidget(self.pB_flash)
        self.horizontalLayout_2.addLayout(self.verticalLayout)
        self.line = QtWidgets.QFrame(self.horizontalLayoutWidget)
        self.line.setFrameShape(QtWidgets.QFrame.VLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName(line)
        self.horizontalLayout_2.addWidget(self.line)
        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
        self.verticalLayout_3.setObjectName(verticalLayout_3)
        self.pB_search = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.pB_search.setObjectName(pB_search)
        self.verticalLayout_3.addWidget(self.pB_search)
        self.line_6 = QtWidgets.QFrame(self.horizontalLayoutWidget)
        self.line_6.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_6.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_6.setObjectName(line_6)
        self.verticalLayout_3.addWidget(self.line_6)
        self.label_port = QtWidgets.QLabel(self.horizontalLayoutWidget)
        self.label_port.setObjectName(label_port)
        self.verticalLayout_3.addWidget(self.label_port)
        self.line_5 = QtWidgets.QFrame(self.horizontalLayoutWidget)
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName(line_5)
        self.verticalLayout_3.addWidget(self.line_5)
        self.label_status = QtWidgets.QLabel(self.horizontalLayoutWidget)
        self.label_status.setAlignment(QtCore.Qt.AlignCenter)
        self.label_status.setObjectName(label_status)
        self.verticalLayout_3.addWidget(self.label_status)
        self.line_2 = QtWidgets.QFrame(self.horizontalLayoutWidget)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName(line_2)
        self.verticalLayout_3.addWidget(self.line_2)
        self.horizontalLayout_2.addLayout(self.verticalLayout_3)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 623, 26))
        self.menubar.setObjectName(menubar)
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName(statusbar)
        MainWindow.setStatusBar(self.statusbar)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate(MainWindow, MainWindow))
        self.cB_flashMaster.setText(_translate(MainWindow, *****************))
        self.cB_genFW.setText(_translate(MainWindow, Flash generic firmware))
        self.pB_flash.setText(_translate(MainWindow, Let\'s flash))
        self.pB_search.setText(_translate(MainWindow, Search COM))
        self.label_port.setText(_translate(MainWindow, PORT COM :))
        self.label_status.setText(_translate(MainWindow, Not flashed yet))


if __name__ == __main__:
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

Am încerca să urmeze cele tutorial și unele alte

De fiecare dată, când setupUi () este numit în main.py ei trec la fel de sine ca argument, chiar dacă setupUi () este definit cu un argument doilea (din QWidgets). Mă înțelege este de ce setupUi () este numit într-o clasă care primesc QWidget ca argument și REFERE de sine să-l. Dar când am rulează main.py meu:

import sys
import subprocess as s
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from GUI import Ui_MainWindow
import serial.tools.list_ports

class MyMainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow
        self.ui.setupUi(self)

        self.ui_pB_search.clicked.connect(self.search())
        self.ui.pB_flash.clicked.connect(self.flash())

    def flash(self):
        self.ui.label_status.setText(****************)

        if self.ui.cB_flashMaster.isChecked() == True:
            d.infobox(*******************)
            s.call([flashMASTER.bat])

        self.ui.label_status.setText(***************)
        s.call([flashSLAVE.bat])

        if self.ui.cB_genFW.isChecked() == True:
            self.ui.label_status.setText(**************)
            s.call([genFW.bat])

if __name__ == __main__:
    app = QApplication(sys.argv)
    ex = MyMainWindow()
    sys.exit(app.exec_())

(Am funcția de ștergere fără referință cu Qt pentru o mai bună lizibilitate) Așa că atunci când am alerga main.py am această eroare:

Traceback (apel cele mai recente Ultima): File main.py, linia 79, în ex = MyMainWindow ()

Fișier main.py, linia 13, în init self.ui.setupUi (auto)

TypeError: setupUi () lipsește obligatoriu 1 argument pozițional: 'msgctxt'

Întrebat 24/10/2019 la 12:54
sursa de către utilizator
În alte limbi...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more