凌的博客

您现在的位置是:首页  > 学无止境 > python

python

pyqt5 嵌套布局

2019-08-24python0
#! /usr/bin/python
#-*- coding: utf-8 -*-
# author:jatvsjat
# datetime:2019/8/24 12:19
# software: PyCharm


import sys
from PyQt5.QtWidgets import QApplication,QPushButton,QWidget,QHBoxLayout,QVBoxLayout,QGridLayout,QFormLayout

class MyWindow(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()


    def initUI(self):
        #初始化 总框架
        wlayout = QHBoxLayout()

        #创建 4个子框架
        hlayout = QHBoxLayout()
        vlayout = QVBoxLayout()
        glayout = QGridLayout()
        flayout = QFormLayout()

        #创建按钮
        hlayout.addWidget(QPushButton("1"))
        hlayout.addWidget(QPushButton("2"))

        vlayout.addWidget(QPushButton("3"))
        vlayout.addWidget(QPushButton("4"))


        glayout.addWidget(QPushButton("5"),0,0)
        glayout.addWidget(QPushButton("6"),0,1)
        glayout.addWidget(QPushButton("7"),1,0)
        glayout.addWidget(QPushButton("8"),1,1)


        flayout.addWidget(QPushButton("9"))
        flayout.addWidget(QPushButton("10"))
        flayout.addWidget(QPushButton("11"))
        flayout.addWidget(QPushButton("12"))

        # 创建 4个控件
        hwg = QWidget()
        vwg = QWidget()
        gwg = QWidget()
        fwg = QWidget()

        # 子框架布局 塞进 控件
        hwg.setLayout(hlayout)
        vwg.setLayout(vlayout)
        gwg.setLayout(glayout)
        fwg.setLayout(flayout)

        # 控件导入 总布局
        wlayout.addWidget(hwg)
        wlayout.addWidget(vwg)
        wlayout.addWidget(gwg)
        wlayout.addWidget(fwg)

        #窗体导入布局
        self.setLayout(wlayout)
        self.show()






if __name__ == "__main__":
    app = QApplication(sys.argv)
    mywin = MyWindow()
    sys.exit(app.exec_())



1.png

如果本文对您有所帮助,请支持下本站哦!!!^_^

文章评论

0条评论