PyQt5-网格布局(QGridLayout)-10
Posted ygzhaof
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PyQt5-网格布局(QGridLayout)-10相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章