发布时间:2023-02-18 12:00
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton,
QHBoxLayout, QVBoxLayout, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
okButton = QPushButton(\"OK\")
cancelButton = QPushButton(\"Cancel\")
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton)
vbox = QVBoxLayout()
vbox.addStretch(1)#伸展因子
vbox.addLayout(hbox)
self.setLayout(vbox)
self.setGeometry(300, 300, 300, 150)
self.setWindowTitle(\'Buttons\')
self.show()
if __name__ == \'__main__\':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import (QWidget, QGridLayout,
QPushButton, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
grid = QGridLayout()
self.setLayout(grid)#我们创建一个网格的按钮。
names = [\'Cls\', \'Bck\', \'\', \'Close\',#这些按钮标签
\'7\', \'8\', \'9\', \'/\',
\'4\', \'5\', \'6\', \'*\',
\'1\', \'2\', \'3\', \'-\',
\'0\', \'.\', \'=\', \'+\']
positions = [(i, j) for i in range(5) for j in range(4)]
for position, name in zip(positions, names):#我们创建一个网格中的位置的列表
if name == \'\':
continue
button = QPushButton(name)
grid.addWidget(button, *position)
self.move(300, 150)
self.setWindowTitle(\'Calculator\')
self.show()
#控件可以在网格中跨越多个行列
import sys
from PyQt5.QtWidgets import (QWidget, QLabel, QLineEdit,
QTextEdit, QGridLayout, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
title = QLabel(\'Title\')#标签文本
author = QLabel(\'Author\')
review = QLabel(\'Review\')
titleEdit = QLineEdit()#文本编辑处
authorEdit = QLineEdit()
reviewEdit = QTextEdit()
grid = QGridLayout()#表格布局
grid.setSpacing(10)
grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1)#创建一个网格布局和设置组件之间的间距。
grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1)
grid.addWidget(review, 3, 0)
grid.addWidget(reviewEdit, 3, 1, 5, 1)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle(\'Review\')
self.show()
if __name__ == \'__main__\':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import QWidget, QLabel, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
lbl1 = QLabel(\'Zetcode\', self)
lbl1.move(15, 10)#我们使用move()方法来控制控件的位置
lbl2 = QLabel(\'tutorials\', self)
lbl2.move(35, 40)
lbl3 = QLabel(\'for programmers\', self)
lbl3.move(55, 70)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle(\'Absolute\')
self.show()
if __name__ == \'__main__\':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
用 Python 制作可视化 GUI 界面,一键实现将头像转成动漫风!
ENVI_IDL:使用反距离权重法选取最近n个点插值(底层实现)并输出为Geotiff格式(效果等价于Arcgis中反距离权重插值)
ASP.NET中Response.BufferOutput属性的使用技巧
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
MySQL8.0.26安装配置教程(windows 64位)
MySQL对JOIN做了那些不为人知的优化《死磕MySQL系列 十七》