当前位置:网站首页>使用pyQt 网格布局(QGridLayout)创建一个计算器
使用pyQt 网格布局(QGridLayout)创建一个计算器
2022-08-08 06:20:00 【波尔德】
import sys
from PyQt5.QtWidgets import *
class Example(QWidget):
def __init__(self, parent=None):
super(Example, self).__init__(parent)
self.initUI()
def initUI(self):
grid = QGridLayout()
self.setLayout(grid)
items = ['计算', 'back', '', 'close',
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+'
]
# 指定位置
positions = [(i, j) for i in range(5) for j in range(4)]
#print(positions)
# 让button的位置和名字做一个捆绑
for postion, name in zip(positions, items):
# 如果名字为空,则跳过。不创建按钮,也不安放按钮位置
if name == '':
continue
# 创建button控件,并给 button 赋值
button = QPushButton(name)
# 如果有多个位置参数,则利用 *position
grid.addWidget(button, *postion)
# 指定窗口在屏幕上显示的初试位置
self.move(800, 150)
self.setWindowTitle("网格布局")
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = Example()
demo.show()
sys.exit(app.exec_())
运行效果截图:
边栏推荐
- Shorthand for flex layout properties
- 4G/5G频谱资源协同关键技术
- tkinter-TinUI-xml实战(7)PDF分页与合并
- Runtime——KVC,KVO原理
- 2-SAT
- ax.patches 表示什么?
- MySQL database
- Why should Latches be avoided in digital IC design?
- Efficient and beautiful scrolling component Slivers of Flutter tutorial (tutorial includes source code)
- 卷积神经网络 图像识别,卷积神经网络 图像处理
猜你喜欢
随机推荐
PAT乙级-B1029 旧键盘(20)
oracle的插入sql错误
轮播文字! QPainter
Neural network to solve what problem, neural network results is not stable
Test and Debug
np.iinfo和 np.finfo的用法
APISIX Ingress v1.5-rc1 发布
The amount of parameters and calculation of neural network, is the neural network a parametric model?
【笔记工具】
日常bug小结:
仿QQ好友列表,QListWidget!
Shorthand for flex layout properties
Why should Latches be avoided in digital IC design?
What does the "busy" Polkadot latest effort mean for DOT investors?
【RPC】Mercury RPC
String title parsing
Leetcode sword 】 refers to the Offer (special commando) summary
oracle insert sql error
Kingbase ES创建过程,报错:PL/SQL block not end correctly
人机对话中得意图识别(关键词提取,svm工具)









