用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'的解决方法的更多相关文章

  1. facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'

    报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute ' ...

  2. zc.buildout构建项目时报错‘AttributeError: '_NamespacePath' object has no attribute 'sort'’

    在使用zc.buildout构建项目时如果碰到‘AttributeError: '_NamespacePath' object has no attribute 'sort'’报错: An inter ...

  3. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  4. 关于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处理器进行项目的 ...

  5. py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】

    问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图  或者  解决方法:   将”driver ...

  6. dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'

    有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...

  7. CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法

    CCS5 建立SYS/BIOS工程时报错“cannot find file "./configPkg/linker.cmd" bios”的解决方法 报错 #10008-D cann ...

  8. 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'

    在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...

  9. Django2.2报错 AttributeError: 'str' object has no attribute 'decode'

    准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...

随机推荐

  1. Azure Data Factory(四)集成 Logic App 的邮件通知提醒

    一,引言 上一篇有介绍到使用Azure Data Factory 复制数据,然后有集成 Azure DevOps 实现CI/CD,但是对于真正的项目来说,这些肯定是不够的,比如说在执行 Azure P ...

  2. Mongodb和Hbase的对比

    Mongodb和Hbase的对比 1.Mongodb bson文档型数据库,整个数据都存在磁盘中,hbase是列式数据库,集群部署时每个familycolumn保存在单独的hdfs文件中. 2.Mon ...

  3. netfilter 的扩展功能 helper tftp-nat

    /* 需要对conntrack进行功能扩展的协议,会初始化一个struct nf_conntrack_helper 实例,把该实例注册到Netfilter中管理的全局哈希表中. 查找helper使用的 ...

  4. day002|python基础回顾2

    目录 00 上节课复习 01 基本数据类型 02 与用户交互 03 运算符 04 流程运算之if判断 05 流程判断之while循环 06 TEST 00 上节课复习 ""&quo ...

  5. spring 2.5 基础知识和与其他框架的集成

    spring环境搭建: 一:导入spring2.5所需的包,在classpath目录下建一个名为"beans.xml"模板文件: <?xml version="1. ...

  6. rbd的数据在哪里

    创建一个rbd [root@mytest ~]# rbd create test1 --size 4000 查看rbd信息 [root@mytest ~]# rbd info test1 rbd im ...

  7. [LeetCode题解]19. 删除链表的倒数第N个节点 | 双指针 + 一次遍历

    解题思路 双指针:第一个指针先走 n 步,然后两个指针同时走. 这里要注意当链表长度<=n,要删除头节点. 代码 /** * Definition for singly-linked list. ...

  8. SixLabors.ImageSharp 实践小结

    前言 之前写过一篇 Linux/Docker 中使用 System.Drawing.Common 踩坑小计, 当时主要是有一块图像处理的需要从 .net framework 迁移到 .net core ...

  9. 【appium】appium自动化入门之环境搭建(上)

     第 1 章 环境搭建 1.1 android-sdk 环境 前言 appium可以说是做app 适用最广泛的一个自动化框架,它的主要优势是支持android和ios ,另外脚本语言也是支持 java ...

  10. Python一行式代码

    # 简易Web Server,可以直接快速共享文件 python -m http.server # 脚本性能分析 python -m cProfile my_script.py # 列表辗平 impo ...