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

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

在学习Qt的过程中,遇到错误AttributeError: 'Ui_MainWindow' object has no attribute 'setupUI' 代码如下:

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

以下代码是.ui

生成的.py文件
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"))

你粗心搞错了,Ui_MainWindow中定义的函数是setupUi,调用时用的是setupUI,一个是i,另一个是是I,名字不一样所以报错,函数名可以改成一样的