PyQt5--GridLayout

2018-09-18 06:43:33来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

 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             

 

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:PyQt5---firstwindow

下一篇:PyQt5---ChangeIcon