L
L
LRXZ2020-08-24 19:21:24
Python
LRXZ, 2020-08-24 19:21:24

How to solve problems with Python inheritance?

Using a design created in QT 5 designer and inheriting it in my own class, I catch the error that my class does not have a function that is in design_login.py

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(229, 317)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.labelHost = QtWidgets.QLabel(self.centralwidget)
        self.labelHost.setObjectName("labelHost")
        self.verticalLayout.addWidget(self.labelHost)
        self.lineEditHost = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEditHost.setObjectName("lineEditHost")
        self.verticalLayout.addWidget(self.lineEditHost)
        self.labelPort = QtWidgets.QLabel(self.centralwidget)
        self.labelPort.setObjectName("labelPort")
        self.verticalLayout.addWidget(self.labelPort)
        self.lineEditPort = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEditPort.setObjectName("lineEditPort")
        self.verticalLayout.addWidget(self.lineEditPort)
        self.labelLogin = QtWidgets.QLabel(self.centralwidget)
        self.labelLogin.setObjectName("labelLogin")
        self.verticalLayout.addWidget(self.labelLogin)
        self.lineEditLogin = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEditLogin.setObjectName("lineEditLogin")
        self.verticalLayout.addWidget(self.lineEditLogin)
        self.labelPassword = QtWidgets.QLabel(self.centralwidget)
        self.labelPassword.setObjectName("labelPassword")
        self.verticalLayout.addWidget(self.labelPassword)
        self.lineEditPassword = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEditPassword.setObjectName("lineEditPassword")
        self.verticalLayout.addWidget(self.lineEditPassword)
        self.ButtonConnect = QtWidgets.QPushButton(self.centralwidget)
        self.ButtonConnect.setObjectName("ButtonConnect")
        self.verticalLayout.addWidget(self.ButtonConnect)
        MainWindow.setCentralWidget(self.centralwidget)
        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", "Login window"))
        self.labelHost.setText(_translate("MainWindow", "Host address"))
        self.labelPort.setText(_translate("MainWindow", "Port"))
        self.labelLogin.setText(_translate("MainWindow", "Login"))
        self.labelPassword.setText(_translate("MainWindow", "Password"))
        self.ButtonConnect.setText(_translate("MainWindow", "Connect"))

-----------------------------------------------------------------------------------------------------------------------------------

GUI_login.py
from PyQt5 import QtWidgets as qtw
import design_login
import Connection
import sys


class GUI(qtw.QMainWindow, design_login.Ui_MainWindow):
    Host = " "
    Port = 9090
    login = " "
    password = " "

    def __init__(self):
        super().__init__()
        self.setupUI(self)
        self.lineEditPassword.Password()
        self.ButtonConnect.clicked.connect(self.read_n_connect())

    def read_n_connect(self):
        Host = self.lineEditHost.text()
        Port = self.lineEditPort.text()
        login = self.lineEditLogin.text()
        password = self.lineEditPassword.text()
        client = Connection.Client(Host, Port, login, password)


if __name__ == '__main__':
    app = qtw.QApplication(sys.argv)
    ex = GUI()
    ex.show()
    sys.exit(app.exec_())


ошибка:

Traceback (most recent call last):
File "/home/lrxz/PycharmProjects/Client/GUI_login.py", line 29, in
ex = GUI()
File "/home/lrxz/PycharmProjects/Client/GUI_login.py", line 15, in __init__
self.setupUI(self)
AttributeError: 'GUI' object has no attribute 'setupUI'

Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MechanicZelenyy, 2020-08-24
@LRXZ

Firstly, you have setupUI written differently everywhere, and secondly, you do not pass all the necessary arguments, and thirdly, well, use normal IDEs, such errors are immediately highlighted there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question