python中调用pyqt5创建窗口实现pushbutton关闭窗口效果,应该向函数之中添加什么用于不显示none?

题目描述

如何解决运行后显示'NoneType' object has no attribute 'setupUi'的错误,该向三个函数之中添加什么语句?

题目来源及自己的思路

相关代码

粘贴代码文本(请勿用截图)

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'

#

# Created by: PyQt5 UI code generator 5.15.7

#

# WARNING: Any manual changes made to this file will be lost when pyuic5 is

# run again. Do not edit this file unless you know what you are doing.

import sys

class QtWidgets:

@classmethod

def QApplication(cls, argv):

pass

@classmethod

def QMainWindow(cls):

pass

def Ui_MainWindow():

pass

if __name__ == '__main__':

app = QtWidgets.QApplication(sys.argv)

MainWindow = QtWidgets.QMainWindow()

ui = Ui_MainWindow()

ui.setupUi(MainWindow)

MainWindow.show()

sys.exit(app.exec_())

from PyQt5 import QtCore, QtWidgets

class Ui_MainWindow(object):

def setupUi(self, MainWindow):

MainWindow.setObjectName("MainWindow")

MainWindow.resize(800, 600)

self.centralwidget = QtWidgets.QWidget(MainWindow)

self.centralwidget.setObjectName("centralwidget")

self.pushButton = QtWidgets.QPushButton(self.centralwidget)

self.pushButton.setGeometry(QtCore.QRect(260, 90, 75, 23))

self.pushButton.setObjectName("pushButton")

MainWindow.setCentralWidget(self.centralwidget)

self.menubar = QtWidgets.QMenuBar(MainWindow)

self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))

self.menubar.setObjectName("menubar")

MainWindow.setMenuBar(self.menubar)

self.statusbar = QtWidgets.QStatusBar(MainWindow)

self.statusbar.setObjectName("statusbar")

MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)

self.pushButton.clicked.connect(self.pushButton.close) # type: ignore

QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):

_translate = QtCore.QCoreApplication.translate

MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

self.pushButton.setText(_translate("MainWindow", "PushButton"))

你期待的结果是什么?实际看到的错误信息又是什么?

python中调用pyqt5创建窗口实现pushbutton关闭窗口效果,应该向函数之中添加什么用于不显示none?

以上是 python中调用pyqt5创建窗口实现pushbutton关闭窗口效果,应该向函数之中添加什么用于不显示none? 的全部内容, 来源链接: utcz.com/p/938654.html

回到顶部