在学习qt时遇到了报错:AttributeError: 'W' object has no attribute 'setupUi'
检查了几次,不知道哪里错
代码:
```python
import sys
import PySide2.QtWidgets
from ui_window import Ui_MainWindow
class W(PySide2.QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.show()
self.pbtn_zz.clicked.connect(self.select_file)
def select_file(self):
self.xg_lb.setText("测试成功")
if __name__ == "__main__":
app = PySide2.QtWidgets.QApplication(sys.argv)
window = W()
sys.exit(app.exec_())
ui_window的代码:
```python
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.verticalLayout = QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(u"verticalLayout")
self.le_sr = QLineEdit(self.centralwidget)
self.le_sr.setObjectName(u"le_sr")
self.verticalLayout.addWidget(self.le_sr)
self.xg_lb = QLabel(self.centralwidget)
self.xg_lb.setObjectName(u"xg_lb")
self.verticalLayout.addWidget(self.xg_lb)
self.pbtn_zz = QPushButton(self.centralwidget)
self.pbtn_zz.setObjectName(u"pbtn_zz")
self.verticalLayout.addWidget(self.pbtn_zz)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QStatusBar(MainWindow)
self.statusbar.setObjectName(u"statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.xg_lb.setText(QCoreApplication.translate("MainWindow", u"\u6548\u679c", None))
self.pbtn_zz.setText(QCoreApplication.translate("MainWindow", u"\u5f00\u59cb\u8bc5\u5492", None))
# retranslateUi