欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【PyQt5】主窗口类型与代码演示

程序员文章站 2022-05-28 11:08:03
...

在PyQt5中有三种窗口:

QMainWindow:可以包含菜单栏、工具栏、状态栏和标题栏,是最常见的窗口形式。
QDialog:是对话窗口的基类。没有菜单栏、工具栏、状态栏。
QWidget:不确定主窗口的用途,就使用QWidget。

创建窗口代码如下:

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtGui import QIcon

class MainWindow(QMainWindow):
    def __init__(self,parent=None):
        super(MainWindow,self).__init__(parent)

        # 设置主窗口标题
        self.setWindowTitle('第一个主窗口应用')

        # 设置窗口尺寸
        self.resize(400,300)

		# 设置状态条
        self.status = self.statusBar()
        
		# 设置消息内容
        self.status.showMessage('只显示5秒的消息',5000)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('./images/index.jpg'))  # 需要添加图标
    main = MainWindow()
    main.show()

    sys.exit(app.exec_())

【PyQt5】主窗口类型与代码演示

相关标签: PyQt5 pyqt