PyQt5--GridLayout

 1 # -*- coding:utf-8 -*-
 2 '''
 3 Created on Sep 13, 2018
 4 
 5 @author: SaShuangYiBing
 6 '''
 7 import sys
 8 from PyQt5.QtWidgets import QApplication,QWidget,QPushButton,QGridLayout
 9 
10 class New_test(QWidget):
11     def __init__(self):
12         super().__init__()
13         self.initUI()
14         
15     def initUI(self):
16         grid = QGridLayout()
17         self.setLayout(grid)
18         
19         names = ['Cls','Bck','','Close','7','8','9','/','4','5','6','*','1','2','3','-','0','.','=','+']
20         
21         positions = [(i,j) for i in range(5) for j in range(4)]
22         
23         print (list(zip(positions,names)))
24         
25         for position,name in zip(positions,names):
26             if name == '':
27                 continue
28             button = QPushButton(name)
29             grid.addWidget(button,*position)
30         
31         self.move(300,150)
32         self.setWindowTitle('Calculator')
33         self.show()
34         
35 if __name__ == "__main__":
36     app = QApplication(sys.argv)
37     ex = New_test()
38     sys.exit(app.exec_())              
39             

猜你喜欢

转载自www.cnblogs.com/SaShuangYiBing/p/9641955.html