Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

QT5: reports AttributeError: 'Ui_MainWindow' object has no attribute 'setupUI'

In the process of learning Qt, I encountered an error AttributeError: ‘Ui_MainWindow’ object has no attribute ‘setupUI’
code show as below:

# This Python file uses the following encoding: utf-8
import sys
from windowUI import Ui_MainWindow
from PySide2.QtWidgets import Application, QMainWindow

if __name__ == "__main__":
    app = Application([])
    aw = Ui_Mainwindow()
    window = OMainwindow()
    aw.setupUI(window)
    window. show()
    sys.exit(app.exec_())

The following code is the .py file generated by .ui

class Ui_MainWindow(object):
    def setupui(self, Mainwindow):
        Mainwindow.setobjectName("MainWindow")
        Mainwince.resize(800, 600)
        MainWinauw.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setobjectName("centralwidget")
        self.commandLinkButton = Qtwidgets.QCommandLinkButton(self. centralwidget)
        self.commandLinkButton.setGeometry(QtCore.QRect(330, 230, 187, 41))
        self.commandLinkButton.set0bjectName("commandLinkButton")
        MainWindow.setCentralwidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(@tCore.QRect (0, 0, 800, 27))
        self.menubar.set0bjectName("menubar")
        Mainwindow.setMenuBar(self. menubar)
        self.statusbar = Qtwidgets.QStatusBar(MainWindow)
        self.statusbar.setobjectName("statusbar")
        Mainwindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetalbject.connectSlotsByName(MainWindow)
    def retranslateli(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        Mainwindow.setwindowTitle(_translate("MainWindow", 
        "MainWindow"))
         self.commandLinkButton.setText(_translate("MainWindow","test"))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You made a mistake due to carelessness, The function defined in Ui_MainWindow is setupUi, and setupUI is used when calling, one is i, the other is I, the names are different, so an error is reported, and the function name can be changed to the same.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading