PyQt5 setupUi () nodig 1 meer positionele argument

stemmen
0

Ik heb een zoekopdracht met thoses zinnen setupUi () ontbreekt 1 positionele argument StackOverflow gemaakt, maar niet gevonden antwoord op mijn probleem.

Ik heb mijn ontwerp gemaakt op Qt Designer en te converteren naar .py met pyuic5. Hier is de code te genereren:

    # -*- 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_())

Ik heb proberen om die te volgen handleiding en enkele andere degenen

Iedere keer, wanneer setupUi () wordt aangeroepen in de main.py ze net voorbij zelf als argument zelfs als setupUi () is definitief met een 2e argument (van QWidgets). Ik ben te begrijpen is waarom setupUi () heet in een klasse die QWidget te ontvangen als een argument en zelf refere om het. Maar als ik het uitvoeren van mijn main.py:

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_())

(Ik heb wisfunctie zonder verwijzing met Qt voor een betere leesbaarheid) Dus als ik run main.py Ik heb deze fout kreeg:

Traceback (meest recente oproep vorige): File main.py, lijn 79, in ex = MyMainWindow ()

File main.py, lijn 13, in init self.ui.setupUi (zelf)

TypeError: setupUi () ontbreekt 1 vereiste positionele argument: 'MainWindow'

De vraag is gesteld op 24/10/2019 om 12:54
bron van user
In andere talen...                            

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