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             

 

 

转载于:https://www.cnblogs.com/TwCsLj/p/9641955.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值