PyQt程序执行时报错:AttributeError: 'winTest' object has no attribute 'setCentralWidget'的解决方法
用QtDesigner设计了一个UI界面,保存在文件Ui_wintest.ui中,界面中使用了MainWindow窗口,窗口名字也叫MainWindow,用PyUIC将其转换成了
Ui_wintest.py文件,在其中UI界面类为Ui_MainWindow。
然后编辑了一个主应用代码文件:
from PyQt5.QtWidgets import QMessageBox,QApplication
from PyQt5 import QtWidgets
import sys
import Ui_wintest
showMessage = QMessageBox.question
class winTest(QtWidgets.QWidget,Ui_wintest.Ui_MainWindow ):
def __init__(self):
super(winTest, self).__init__()
self.setupUi(self)
def closeEvent(self,event):
reply = showMessage(self, '警告',"系统将退出,是否确认?", QMessageBox.Yes |QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = winTest()
w.show()
sys.exit(app.exec_())
使用Pycharm进行代码检测没有错误,但执行时报错:
AttributeError: ‘winTest’ object has no attribute ‘setCentralWidget’
经确认是因为主程序的类派生的基类使用错了导致,由于UI界面设计使用了MainWindow,因此在主程序派生的子类必须继承MainWindow,将类定义的语句改成为:
class winTest(QtWidgets.QMainWindow,Ui_wintest.Ui_MainWindow ):
就可以了,同样的,如果UI设计使用的窗口类型是其他类型,最好在主程序派生类的定义时基类就要使用对应类型。

博客地址:https://blog.csdn.net/LaoYuanPython
老猿Python博客文章目录:https://blog.csdn.net/LaoYuanPython/article/details/98245036
PyQt程序执行时报错:AttributeError: 'winTest' object has no attribute 'setCentralWidget'的解决方法的更多相关文章
- facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'
报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute ' ...
- zc.buildout构建项目时报错‘AttributeError: '_NamespacePath' object has no attribute 'sort'’
在使用zc.buildout构建项目时如果碰到‘AttributeError: '_NamespacePath' object has no attribute 'sort'’报错: An inter ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- 关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法
关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法 近期在评估使用NIOS II处理器进行项目的 ...
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法
CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法 报错 #10008-D cann ...
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...
- Django2.2报错 AttributeError: 'str' object has no attribute 'decode'
准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...
随机推荐
- os00
- 运行状态:占用处理机资源运行,处于此状态的进程数小于等于CPU数# 操作系统* 进程和线程 * [进程和线程有什么区别?](#进程和线程有什么区别) * [进程间通信有哪些方式?](# ...
- C#两行代码实现三维地球
一. 为什么要用三维地球? 三维地球是地理信息技术的一个重要发展方向,相比较二维地图技术,三维地球最大的特点是更直观更形象地表达地理信息和空间上的方位.我们可以在三维气象模拟. ...
- 卡特兰数 洛谷P1641 [SCOI2010]生成字符串
卡特兰数 参考博客 介绍 卡特兰数为组合数学中的一种特殊数列,用于解决一类特殊问题 设\(f(n)\)为卡特兰数的第n项 其通项公式为 \[f(n)=\frac{2n\choose n}{n+1} \ ...
- 7. 基于MLlib的机器学习
*以下内容由<Spark快速大数据分析>整理所得. 读书笔记的第七部分是讲的是如何使用Spark中提供机器学习函数的MLlib库,在集群中并行运行机器学习算法. MLlib是Spark中提 ...
- 3. Spark常见数据源
*以下内容由<Spark快速大数据分析>整理所得. 读书笔记的第三部分是讲的是Spark有哪些常见数据源?怎么读取它们的数据并保存. Spark有三类常见的数据源: 文件格式与文件系统:它 ...
- 13Linux之磁盘管理
13Linux之磁盘管理 目录 13Linux之磁盘管理 13 磁盘管理 13.1 两种分区格式 13.1.1 磁盘命名 13.1.2 mbr 13.1.3 gpt 13.2 制作文件系统并且挂载 1 ...
- 希捷powerchoice磁盘休眠功能配置方法
本篇关于希捷磁盘休眠的配置方法 准备设置的软件 下载地址 https://raw.githubusercontent.com/Seagate/ToolBin/master/SeaChest/Power ...
- oracle的迁移工作
1.创建新数据库用户 1).创建用户和分配权限 sqlplus / as sysdba create user ENFRC_TEST_GZ_TMP identified by ENFRC_TEST_G ...
- EF Core 二 、 入门 EF Core
入门EF Core 我们将开始真正的EF之旅了,这里使用SqlServer数据,然后DbFirst: 为嘛使用SqlServer,目前公司的整体业务全部在SqlSever,所以很多产品业务都是依托于这 ...
- Java 中常见的细粒度锁实现
上篇文章大致说了下 ReentrantLock 类的使用,对 ReentrantLock 类有了初步的认识之后让我们一起来看下基于 ReentrantLock 的几种细粒度锁实现. 这里我们还是接着用 ...