码迷,mamicode.com
首页 > 其他好文 > 详细

PyQt5-网格布局(QGridLayout)-10

时间:2018-09-30 18:11:59      阅读:858      评论:0      收藏:0      [点我收藏+]

标签:col   bubuko   print   int   tla   continue   add   image   idg   

 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))

技术分享图片

 

PyQt5-网格布局(QGridLayout)-10

标签:col   bubuko   print   int   tla   continue   add   image   idg   

原文地址:https://www.cnblogs.com/ygzhaof/p/9732628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!