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

标题: python_白李娜_20210126 [打印本页]

作者: つ兜兜里没糖    时间: 2021-1-26 20:45
标题: python_白李娜_20210126
一、整理笔记
1.数据库的连接和数据的增删改查
import mysql.connector
# 连接到指定的数据库
db = mysql.connector.connect(host='localhost',user='root',password='123456',database='JY40',port = '3307')
# 获取游标
cursor = db.cursor()
# 修改id = 3 的元素,pwd='abc'
cursor.execute('update user set pwd=%s where id=%s',('abc',3))
#删除id = 2 的元素
cursor.execute('delete from user where id=%s',(17,))
db.commit()
#分页查询(page-1)*n  n
cursor.execute('select * from user limit 5,5')
result = cursor.fetchall()
print(result)
2.创建窗口
from PyQt5.QtWidgets import QApplication,QWidget
from PyQt5.QtGui import QIcon
import sys
class Example(QWidget):
    def __init__(self):
        # 调用父类的构造方法
        super().__init__()
        self.initUI()
    def initUI(self):
        # 设置窗口大小和位置
        self.setGeometry(300,300,300,200)
        # 设置窗口标题
        self.setWindowTitle('图标')
        # 修改图标
        self.setWindowIcon(QIcon(r'python\day08\f9.png'))
        #显示窗口
        self.show()
3.设置窗口的按钮
    def initUI(self):
        #创建提示
        self.setToolTip('这是一个<b>QWidget</b>组件')
        #创建按钮
        btn = QPushButton('按钮',self)
        #创建提示  u 下划线 i 斜体
        btn.setToolTip('这是一个<u>按钮</u>组件')
        #移动按钮的位置
        btn.move(100,100)
        self.setGeometry(300,300,300,200)
        self.setWindowTitle('提示信息')
        self.show()
4.给按钮绑定功能
    def initUI(self):
        #创建按钮
        btn = QPushButton('按钮',self)
        #移动按钮位置
        btn.move(100,100)
        #给按钮绑定功能     当点击按钮时才去执行,
        btn.clicked.connect(self.f)
        # btn.clicked.connect(QCoreApplication.instance().quit)#点击按钮退出
        self.setGeometry(300,300,300,200)
        self.setWindowTitle('给按钮绑定功能')
        self.show()
    def f(self):
        print('测试按钮功能!')
        #创建水平布局
        hbox = QHBoxLayout()
        hbox.addWidget(ok)
        hbox.addStretch(1)
        hbox.addWidget(cancel)
        #创建垂直布局
        vbox = QVBoxLayout()
        vbox.addStretch(2)
        vbox.addLayout(hbox)
        # self.setLayout(hbox)
        self.setLayout(vbox)
        self.setGeometry(300,300,300,200)
        self.setWindowTitle('框式布局')
        self.show()






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