zoukankan      html  css  js  c++  java
  • 【PyQt5 学习记录】002:添加部件及网格布局

     1 #!/usr/bin/python3
     2 # -*- coding:utf-8 -*-
     3 
     4 import sys
     5 from PySide2.QtWidgets import (QApplication,
     6                                QWidget,
     7                                QGridLayout,
     8                                QPushButton,
     9                                QLabel)
    10 
    11 
    12 class MainWindow(QWidget):
    13     def __init__(self):
    14         super().__init__()
    15 
    16         # 设置一个标签
    17         label = QLabel('This is a Label.')
    18         # 设置一个按钮
    19         button = QPushButton('This is a button.')
    20         # 设置一个网格布局
    21         grid = QGridLayout()
    22         # 通过 addWidget 为布局添加部件:
    23         # 添加一个位于 0 行 0 列,跨 1 行 2 列的label组件
    24         grid.addWidget(label, 0, 0, 1, 2)
    25         # 添加一个位于 1 行 1 列默认大小的button组件
    26         grid.addWidget(button, 1, 1)
    27         # 将布局 grid 添加到窗口
    28         self.setLayout(grid)
    29 
    30         self.resize(300, 300)
    31         self.setWindowTitle('Simple Window')
    32 
    33 
    34 if __name__ == '__main__':
    35     app = QApplication()
    36     window = MainWindow()
    37     window.show()
    38     sys.exit(app.exec_())
    效果如下:

  • 相关阅读:
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    How to build and run ARM Linux on QEMU from scratch
    How to debug Android Native Application with eclipse
  • 原文地址:https://www.cnblogs.com/jmtm/p/9771127.html
Copyright © 2011-2022 走看看