提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
一、学习内容
1. 绝对布局(使用控件的move(x,y)函数)
2. 箱式布局(单行单列)(水平布局:QHBoxLayout和垂直布局:QVBoxLayout)
2.1 addWidget(向布局容器中加入其他控件)
2.2 addStretch(向布局容器中加入伸缩量)
![在这里插入图片描述](https://img-blog.csdnimg.cn/8d3530aaa1314de088cf7b4d233a2b12.png
3. 网格布局(多行多列)
4. 表单布局(处理需要输入的布局:左列标签,右列输入控件)
5. 编辑伙伴(快捷键)
二、完成代码
1. 绝对布局
#coding = 'utf-8'
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.Init_UI()
def Init_UI(self):
self.setGeometry(300,300,400,300)
self.setWindowTitle('学点编程吧')
bt1 = QPushButton('剪刀',self)
bt1.move(50,250)
bt2 = QPushButton('石头',self)
bt2.move(150,250)
bt3 = QPushButton('布',self)
bt3.move(250,250)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
app.exit(app.exec_())
2. 箱式布局
#coding = 'utf-8'
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication, QHBoxLayout)
class Example(QWidget):
def __init__(self):
super().__init__()
self.Init_UI()
def Init_UI(self):
self.setGeometry(300,300,400,300)
self.setWindowTitle('学点编程吧')
bt1 = QPushButton('剪刀', self)
bt2 = QPushButton('石头', self)
bt3 = QPushButton('布', self)
hbox = QHBoxLayout()
hbox.addStretch(1) #增加伸缩量
hbox.addWidget(bt1)
hbox.addStretch(1)#增加伸缩量
hbox.addWidget(bt2)
hbox.addStretch(1)#增加伸缩量
hbox.addWidget(bt3)
hbox.addStretch(6)#增加伸缩量
self.setLayout(hbox)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
app.exit(app.exec_())
3. 栅格布局
#coding = 'utf-8'
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication, QGridLayout, QLCDNumber)
class Example(QWidget):
def __init__(self):
super().__init__()
self.Init_UI()
def Init_UI(self):
grid = QGridLayout()
self.setLayout(grid)
self.setGeometry(300,300,400,300)
self.setWindowTitle('学点编程吧-计算器')
self.lcd = QLCDNumber()
grid.addWidget(self.lcd,0,0,3,0)
grid.setSpacing(10)
names = ['Cls', 'Bc', '', 'Close',
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+']
positions = [(i,j) for i in range(4,9) for j in range(4,8)]
for position, name in zip(positions, names):
if name == '':
continue
button = QPushButton(name)
grid.addWidget(button, *position)
button.clicked.connect(self.Cli)
self.show()
def Cli(self):
sender = self.sender().text()
ls = ['/', '*', '-', '=', '+']
if sender in ls:
self.lcd.display('A')
else:
self.lcd.display(sender)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
app.exit(app.exec_())
4. 表单布局
#coding = 'utf-8'
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication, QFormLayout, QLabel, QLineEdit, QTextEdit)
class Example(QWidget):
def __init__(self):
super().__init__()
self.Init_UI()
def Init_UI(self):
self.setGeometry(300,300,300,200)
self.setWindowTitle('学点编程吧')
formlayout = QFormLayout()
nameLabel = QLabel("姓名")
nameLineEdit = QLineEdit("")
introductionLabel = QLabel("简介")
introductionLineEdit = QTextEdit("")
formlayout.addRow(nameLabel,nameLineEdit)
formlayout.addRow(introductionLabel,introductionLineEdit)
self.setLayout(formlayout)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
app.exit(app.exec_())#coding = 'utf-8'
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QApplication, QFormLayout, QLabel, QLineEdit, QTextEdit)
class Example(QWidget):
def __init__(self):
super().__init__()
self.Init_UI()
def Init_UI(self):
self.setGeometry(300,300,300,200)
self.setWindowTitle('学点编程吧')
formlayout = QFormLayout()
nameLabel = QLabel("姓名")
nameLineEdit = QLineEdit("")
introductionLabel = QLabel("简介")
introductionLineEdit = QTextEdit("")
formlayout.addRow(nameLabel,nameLineEdit)
formlayout.addRow(introductionLabel,introductionLineEdit)
self.setLayout(formlayout)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
app.exit(app.exec_())
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。