zoukankan      html  css  js  c++  java
  • PyQt5-网格布局(QGridLayout)-10

     1 #demo_11:网格布局
     2 import sys
     3 from PyQt5.QtWidgets import  QApplication,QWidget,QGridLayout,QPushButton
     4 
     5 class Example(QWidget):
     6     def __init__(self):
     7         super().__init__()
     8         self.initUI()
     9     def initUI(self):
    10         self.names = ['Cls', 'Bck', '', 'Close',
    11                      '7', '8', '9', '/',
    12                      '4', '5', '6', '*',
    13                      '1', '2', '3', '-',
    14                      '0', '.', '=', '+']
    15         self.options=[(j,i) for j in range(5) for i in range(4)]
    16         self.layout=QGridLayout()
    17         self.setLayout(self.layout)
    18 
    19         for (name,option) in zip(self.names,self.options):
    20             if name=='':continue
    21             btn=QPushButton(name)
    22             self.layout.addWidget(btn,*option)
    23         self.setWindowTitle('Calculator')
    24         self.show()
    25 if __name__=='__main__':
    26     app=QApplication(sys.argv)
    27     e=Example()
    28     sys.exit(app.exec())
    29 
    30 # names = ['Cls', 'Bck', '', 'Close',
    31 #              '7', '8', '9', '/',
    32 #              '4', '5', '6', '*',
    33 #              '1', '2', '3', '-',
    34 #              '0', '.', '=', '+']
    35 # options = [(i, j) for j in range(5) for i in range(4)]
    36 # for position, name in zip(options, names):
    37 #     print(str(position)+"》》"+str(name))

  • 相关阅读:
    c++基础_矩阵乘法
    c++基础_字符串对比
    c++基础_时间转换
    c++基础_特殊回文数
    c++基础_回文数
    c++基础_特殊的数字
    c++基础_杨辉三角形
    c++基础_字母图形
    c++基础_01字串
    java 常用集合类型--以及其特性
  • 原文地址:https://www.cnblogs.com/ygzhaof/p/9732628.html
Copyright © 2011-2022 走看看