PyQt5 setupUI () 1 daha pozisyonel argüman ihtiyaç

oy
0

Ben stackoverflow Thoses cümleler 1 pozisyonel argüman eksik setupUI () ile bir arama yaptık ama benim sorunun cevabı bulundu vermedi.

Qt Designer benim tasarımını yaptı ve pyuic5 ile .py dönüştürmek ettik. İşte oluşturmak kod:

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

O takip etmeye ettik öğretici ve diğer bazı olanları

setupUI () main.py çağrıldığı zaman her şey, onlar sadece setupUI () (QWidgets itibaren) 2. bir argümanla kesin olsa bile argüman olarak kendini geçmektedir. Ben setupUI () buna bir argüman ve kendini refere olarak QWidget almak bir sınıfta denir neden bu kadar anlayış ediyorum. Ama main.py koşturup dururken:

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

(Daha iyi okunabilmesi için Qt ile referans olmadan silme işlevini ettik) Ben main.py çalıştırmak olduğumda bu hata var:

Traceback (en son çağrı son): Dosya main.py, satır 79, ex = MyMainWindow ()

Dosya main.py, satır 13, init self.ui.setupUi (öz)

TypeError: 'MainWindow': setupUI () 1 eksik pozisyonel argüman gerekli

Oluştur 24/10/2019 saat 12:54
kaynak kullanıcı
Diğer dillerde...                            

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