一、整理筆記
1.數(shù)據(jù)庫的連接和數(shù)據(jù)的增刪改查
import mysql.connector
# 連接到指定的數(shù)據(jù)庫
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.創(chuàng)建窗口
from PyQt5.QtWidgets import QApplication,QWidget
from PyQt5.QtGui import QIcon
import sys
class Example(QWidget):
def __init__(self):
# 調(diào)用父類的構(gòu)造方法
super().__init__()
self.initUI()
def initUI(self):
# 設(shè)置窗口大小和位置
self.setGeometry(300,300,300,200)
# 設(shè)置窗口標題
self.setWindowTitle('圖標')
# 修改圖標
self.setWindowIcon(QIcon(r'python\day08\f9.png'))
#顯示窗口
self.show()
3.設(shè)置窗口的按鈕
def initUI(self):
#創(chuàng)建提示
self.setToolTip('這是一個<b>QWidget</b>組件')
#創(chuàng)建按鈕
btn = QPushButton('按鈕',self)
#創(chuàng)建提示 u 下劃線 i 斜體
btn.setToolTip('這是一個<u>按鈕</u>組件')
#移動按鈕的位置
btn.move(100,100)
self.setGeometry(300,300,300,200)
self.setWindowTitle('提示信息')
self.show()
4.給按鈕綁定功能
def initUI(self):
#創(chuàng)建按鈕
btn = QPushButton('按鈕',self)
#移動按鈕位置
btn.move(100,100)
#給按鈕綁定功能 當點擊按鈕時才去執(zhí)行,
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('測試按鈕功能!')
#創(chuàng)建水平布局
hbox = QHBoxLayout()
hbox.addWidget(ok)
hbox.addStretch(1)
hbox.addWidget(cancel)
#創(chuàng)建垂直布局
vbox = QVBoxLayout()
vbox.addStretch(2)
vbox.addLayout(hbox)
# self.setLayout(hbox)
self.setLayout(vbox)
self.setGeometry(300,300,300,200)
self.setWindowTitle('框式布局')
self.show()
|