菁英科技(卓目鸟学苑)- 专注软件测试菁英教育

标题: python-代金鑫-2021.01.26 [打印本页]

作者: 心向未来    时间: 2021-1-26 20:05
标题: python-代金鑫-2021.01.26
今天学习内容: 9:00-17:30
数据库查询数据
cursor.execute('select * from user')
获取查询结果
result = cursor.fetchall()
每个结果封装为一个元祖
for record in result:
        print(record)
cursor.execute('select * from user where id=%s',(2,))
result = cursor.fetchone()
print(result)
分页查询 (page-1)*n  n
cursor.execute('select * from user limit 5,5')
result = cursor.fetchall()
print(result)
ORM Object Relationship Mapping 对象关系映射
查询user表中的所有数据,并封装为一个列表
对表中数据进行曾删改查
安装PYQT5组件模块,进行组件的创建
创建一个窗口
from PyQt5.QtWidgets import QApplication,QWidget
import sys
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = QWidget()
    window.resize(300,200)
    window.move(300,300)
    window.setWindowTitle('测试窗口')
    window.show()
    sys.exit(app.exec_())
对窗口的位置、大小、图标进行修改
def initUI(self):
        # 设置窗口大小和位置
        self.setGeometry(300,300,300,200)
        # 设置窗口标题
        self.setWindowTitle('图标')
        #修改图标
        self.setWindowIcon(QIcon('python\day08\m1.png'))
        # 显式窗口
        self.show()
if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
sys.exit(app.exec_())
给窗口设置提示以及对提示字体进行设置
在窗口中创建按钮以及给按钮设置提示和确定按钮位置
移动按钮位置、给按钮绑定功能
事件 event
    '''
    # 重写QWidgetcloseEvent()方法,
    # 该方法在关闭事件时会发生时会自动调用
    def closeEvent(self,event):
        # print('closeEvent被调用了...')
        # 弹出消息框,并接收用户的选择
        reply = QMessageBox.question(self,'Message','你真的准备退出吗?',QMessageBox.Yes | QMessageBox.No)
        # 根据用户的选择进行处理
        if reply == QMessageBox.Yes:
            event.accept()  # 接受事件
        else:
            event.ignore()  # 忽略事件
按钮的水平和垂直布局 QHBoxLayout, QVBoxLayout
用表格布局法创建一个计算器界面
from PyQt5.QtWidgets import QApplication,QWidget,QPushButton,QGridLayout
import sys
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        # 创建一个表格布局
        grid = QGridLayout()
        self.setLayout(grid)
        # 创建所有按钮的标签
        labels = ['<——','CE','C','Close',
                   '7','8','9','/',
                   '4','5','6','*',
                   '1','2','3','-',
        # 创建按钮的位置参数
        positions = [(x,y) for x in range(5) for y in range(4)]
        # print(positions)
        # 创建按钮并添加到表格中
        for label,position in zip(labels,positions):
            btn = QPushButton(label)
            # grid.addWidget(btn,position[0],position[1])
            grid.addWidget(btn,*position)






欢迎光临 菁英科技(卓目鸟学苑)- 专注软件测试菁英教育 (http://www.zmnxy.com/) Powered by Discuz! X3.4