zoukankan      html  css  js  c++  java
  • 网格布局

    import sys
    from PyQt4 import QtCore, QtGui
    
    class MainWindow(QtGui.QWidget):
        
        def __init__(self, parent = None):
            QtGui.QWidget.__init__(self)
            self.setWindowTitle('grid layout')
            
            names = ['Cls', 'Bck', '','Close', '7', '8', '9', '/', '4', '5', '6', '*', '1', '2', '3','-','0','.', '=', '+']
            
            grid = QtGui.QGridLayout() # 创建一个网格布局
            
            j = 0
            pos = [(0,0), (0,1), (0,2), (0,3),
                   (1,0), (1,1), (1,2), (1,3),
                   (2,0), (2,1), (2,2), (2,3),
                   (3,0), (3,1), (3,2), (3,3),
                   (4,0), (4,1), (4,2), (4,3)]
           
            
            for i in names:
                button = QtGui.QPushButton(i)
                if j == 2:
                    grid.addWidget(QtGui.QLabel(''), 0, 2) # 填补Back和Close按钮之间的空格,使用QLabel部件
                else:
                    grid.addWidget(button, pos[j][0], pos[j][1]) # 使用addWidget()方法,将部件添加到网格布局中
                j = j + 1
                
            self.setLayout(grid)
                     
            
    app = QtGui.QApplication(sys.argv)
    main = MainWindow()
    main.show()
    sys.exit(app.exec_())

  • 相关阅读:
    杭电2060WA
    杭电2060
    UVa10082 没有通过
    百度笔试题目02
    百度笔试题目01
    Q1002 四则运算
    百度笔试题目
    约瑟夫环 详细的分析
    算法导论03
    汉诺塔01
  • 原文地址:https://www.cnblogs.com/xiyuan2016/p/7206618.html
Copyright © 2011-2022 走看看