【10】PyQt面向对象

目录

Qt窗口继承

初始化ui


Qt窗口继承

写一个自定义类继承QWidget

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys


class MyWindow(QWidget):

    def __init__(self, title):
        super().__init__()
        self.setWindowTitle(title)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    window = MyWindow("窗口标题")
    window.show()

    sys.exit(app.exec_())

通过继承QWidget来实现窗体

在构造中,必须调用super函数,否则将出行错误

初始化ui

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys


class MyWindow(QWidget):

    def __init__(self, title):
        super().__init__()
        self.setWindowTitle(title)
        self.init_ui()

    def init_ui(self):
        layout = QHBoxLayout()
    	# ---------------------------------

        # 在这里初始化界面内容
        
    	# ---------------------------------
        self.setLayout(layout)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    window = MyWindow("窗口标题")
    window.show()

    sys.exit(app.exec_())

 

相关推荐

  1. 10PyQt面向对象

    2023-12-07 07:36:01       65 阅读
  2. 10. TypeScript面向对象的类(Class)

    2023-12-07 07:36:01       39 阅读
  3. day16 初始面向对象

    2023-12-07 07:36:01       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-07 07:36:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-07 07:36:01       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-07 07:36:01       82 阅读
  4. Python语言-面向对象

    2023-12-07 07:36:01       91 阅读

热门阅读

  1. tomcat 有哪几种Connector 运行模式(优化)?

    2023-12-07 07:36:01       54 阅读
  2. Mysql的事务日志

    2023-12-07 07:36:01       57 阅读
  3. AIGC: 关于ChatGPT中进行情感分析的功能

    2023-12-07 07:36:01       49 阅读
  4. Visual Studio 快捷键记录

    2023-12-07 07:36:01       47 阅读
  5. Golang WebSocket Ping Pong

    2023-12-07 07:36:01       43 阅读
  6. 【前端设计模式】之单例模式

    2023-12-07 07:36:01       60 阅读
  7. 单例模式(Singleton Pattern)

    2023-12-07 07:36:01       67 阅读
  8. Golang实践录:读取toml配置

    2023-12-07 07:36:01       55 阅读
  9. ElasticSearch 了解文本相似度 TF-IDF吗?

    2023-12-07 07:36:01       47 阅读
  10. Go语言语法上的一些主要特点(1)

    2023-12-07 07:36:01       51 阅读
  11. 人工智能对现代生活的影响

    2023-12-07 07:36:01       48 阅读