前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python pyqt5 QGridLayout网格布局

python pyqt5 QGridLayout网格布局

作者头像
用户5760343
发布2019-07-22 13:41:11
1.4K0
发布2019-07-22 13:41:11
举报
文章被收录于专栏:sktjsktj

-- coding: utf-8 --

""" 【简介】 网格布局管理例子

"""

import sys from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QPushButton

class Winform(QWidget): def init(self, parent=None): super(Winform, self).init(parent) self.initUI()

代码语言:javascript
复制
def initUI(self):
    # 1
    grid = QGridLayout()
    self.setLayout(grid)

    # 2
    names = ['Cls', 'Back', '', 'Close',
             '7', '8', '9', '/',
             '4', '5', '6', '*',
             '1', '2', '3', '-',
             '0', '.', '=', '+']

    # 3
    positions = [(i, j) for i in range(5) for j in range(4)]

    # 4
    for position, name in zip(positions, names):
        if name == '':
            continue

        button = QPushButton(name)
        grid.addWidget(button, *position)

    self.move(300, 150)
    self.setWindowTitle('网格布局管理例子')

if name == "main": app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())


-- coding: utf-8 --

""" 【简介】 网格布局管理例子

"""

import sys from PyQt5.QtWidgets import (QWidget, QLabel, QLineEdit, QTextEdit, QGridLayout, QApplication)

class Winform(QWidget): def init(self, parent=None): super(Winform, self).init(parent) self.initUI()

代码语言:javascript
复制
def initUI(self):
    titleLabel = QLabel('标题')
    authorLabel = QLabel('提交人')
    contentLabel = QLabel('申告内容')

    titleEdit = QLineEdit()
    authorEdit = QLineEdit()
    contentEdit = QTextEdit()

    grid = QGridLayout()
    grid.setSpacing(10)

    grid.addWidget(titleLabel, 1, 0)
    grid.addWidget(titleEdit, 1, 1)

    grid.addWidget(authorLabel, 2, 0)
    grid.addWidget(authorEdit, 2, 1)

    grid.addWidget(contentLabel, 3, 0)
    grid.addWidget(contentEdit, 3, 1, 5, 1)

    self.setLayout(grid)

    self.setGeometry(300, 300, 350, 300)
    self.setWindowTitle('故障申告')

if name == "main": app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.07.22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • -- coding: utf-8 --
  • -- coding: utf-8 --
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档