23.1.29更新
加入了密码页和统计页
此为密码页 sleep()模仿登录加载的卡顿现象
main_win = None
class LoginWin:
def __init__(self):
super().__init__()
self.ui = QUiLoader().load('denglu.ui')
self.ui.button.clicked.connect(self.onLogin)
self.ui.mima.returnPressed.connect(self.onLogin)
def onLogin(self):
mima=self.ui.mima.text()
zhanghao=self.ui.zhanghao.text()
global main_win
# time.sleep(1)
# 实例化另外一个窗口
if zhanghao=="123":
main_win = Stats()
# 显示新窗口
main_win.ui.show()
# 关闭自己
self.ui.close()
else:
QMessageBox.about(self.ui,"error","账号不存在")
if mima=="123":
main_win = Stats()
# 显示新窗口
main_win.ui.show()
# 关闭自己
self.ui.close()
else:
QMessageBox.about(self.ui,"error","密码错误")
# self.sleep()
thread=threading.Thread(target=self.sleep)
thread.start()
def sleep(self):
for i in range(10):
time.sleep(0.01)
#print(i)
此为统计页,没想好统计啥,就统计了身高和体重之间的关系
class Graph():
def __init__(self,x,y):
# PyQt5 直接加载ui文件
# 因为 第三方控件通过promote的定义
# 已经可以知道 控件类所在模块的路径
loader=QUiLoader()
loader.registerCustomWidget(pg.PlotWidget)
#这一步是拿来注册未有的部件的同文件
self.weight=x
self.height=y
self.ui = loader.load("graph.ui")
self.ui.graph.setTitle("身高/体重",
size='18pt')
self.ui.graph.setLabel("left","身高/cm")
self.ui.graph.setLabel("bottom","体重/kg")
self.ui.graph.setBackground('w')
self.ui.graph.plot(self.weight, self.height,pen='k')
此为主干部分
class Stats:
def __init__(self):
#---------------------------------------------------
#读取窗口
#---------------------------------------------------
# 从文件中加载UI定义
struct=QFile('student.ui')
struct.open(QFile.ReadOnly)
struct.close
# 从 UI 定义中动态 创建一个相应的窗口对象
# 注意:里面的控件对象也成为窗口对象的属性了
# 比如 self.ui.button , self.ui.textEdit
self.ui = QUiLoader().load(struct)
self.ui.fasong.clicked.connect(self.handleCalc)
self.ui.lineEdit.returnPressed.connect(self.handleCalc)
self.ui.qingchu.clicked.connect(self.qingchu)
self.ui.tongji.clicked.connect(self.tongji)
def tongji(self):
x=[]
y=[]
for i in range(self.ui.table.rowCount()):
x.append(int(self.ui.table.item(i,4).text()))
y.append(int(self.ui.table.item(i,3).text()))
global sub_win
sub_win=Graph(x,y)
sub_win.ui.show()
self.ui.close()
def qingchu(self):
self.ui.lineEdit.clear()
self.ui.table.setRowCount(0)
self.ui.plaintext.clear()
def handleCalc(self):
method = self.ui.cbox.currentText()
text=self.ui.lineEdit.text()
hang_count = self.ui.table.rowCount()
lie_count = self.ui.table.columnCount()
if "-" in text:
text = [x for x in text.split('-')]
elif " " in text:
text = [x for x in text.split(' ')]
if len(text)==0:
QMessageBox.about(self.ui,"warning","输入不能为空")
if method=="存入":
if len(text)==5:
self.ui.table.insertRow(0)
for i in range(len(text)):
self.ui.table.setItem(0, i, QTableWidgetItem(text[i]))
elif len(text)!=5 and len(text)!=0:
QMessageBox.about(self.ui,"warning","输入有误")
if method=="查找":
if hang_count==0:
QMessageBox.about(self.ui,"警告","表格尚空")
else:
sentence=""
for i in range(hang_count):
for j in range(lie_count):
if text==self.ui.table.item(i,j).text():
for k in range(lie_count):
sentence+=self.ui.table.item(i,k).text()
sentence+='\t'
sentence+='\n'
QMessageBox.about(self.ui,"查询结果",sentence)
if method=="替换":
if hang_count==0:
QMessageBox.about(self.ui,"警告","表格尚空")
else:
for i in range(hang_count):
if self.ui.table.item(i,1).text()==text[0]:
if text[1]=="班级":
self.ui.table.item(i,0).setText(text[2])
break
if text[1]=="姓名":
self.ui.table.item(i,1).setText(text[2])
break
if text[1]=="性别":
self.ui.table.item(i,2).setText(text[2])
break
if text[1]=="身高":
self.ui.table.item(i,3).setText(text[2])
break
if text[1]=="体重":
self.ui.table.item(i,4).setText(text[2])
break
else:
QMessageBox.about(self.ui,"warning","查无此人")
if method=="删除":
count=0
if hang_count==0:
QMessageBox.about(self.ui,"警告","表格尚空")
else:
for i in range(hang_count):
for j in range(lie_count):
if text==str(self.ui.table.item(i,j).text()):
self.ui.table.removeRow(i)
#self.ui.lineEdit.setText('')
count+=1
if count==0:
QMessageBox.about(self.ui,"warning","无从下手")
else:
self.ui.lineEdit.setText('')
self.ui.lineEdit.clear()
if __name__='__main':
app = QApplication(sys.argv)
app.setWindowIcon(QIcon('logo.png'))
wm = LoginWin()
wm.ui.resize(425, 300)
wm.ui.show()
sys.exit(app.exec_())
23.1.25更新
"""
实现功能:1.存入(班级,姓名,性别,年龄,身高,体重)
2.删除
3.替换
4.查找
"""
#---------------------------------------------------
#导入文件
#---------------------------------------------------
from PySide2.QtWidgets import QApplication, QMessageBox
from PySide2.QtUiTools import QUiLoader
from PySide2.QtCore import QFile
from PySide2.QtWidgets import QTableWidgetItem
import time
class Stats:
def __init__(self):
#---------------------------------------------------
#读取窗口
#---------------------------------------------------
# 从文件中加载UI定义
struct=QFile('student.ui')
struct.open(QFile.ReadOnly)
struct.close
# 从 UI 定义中动态 创建一个相应的窗口对象
# 注意:里面的控件对象也成为窗口对象的属性了
# 比如 self.ui.button , self.ui.textEdit
self.ui = QUiLoader().load(struct)
self.ui.fasong.clicked.connect(self.handleCalc)
self.ui.lineEdit.returnPressed.connect(self.handleCalc)
self.ui.qingchu.clicked.connect(self.qingchu)
def qingchu(self):
self.ui.lineEdit.clear()
self.ui.table.setRowCount(0)
self.ui.plaintext.clear()
def handleCalc(self):
method = self.ui.cbox.currentText()
text=self.ui.lineEdit.text()
hang_count = self.ui.table.rowCount()
lie_count = self.ui.table.columnCount()
if "-" in text:
text = [x for x in text.split('-')]
elif " " in text:
text = [x for x in text.split(' ')]
if method=="存入":
if len(text)==5:
self.ui.table.insertRow(0)
for i in range(len(text)):
self.ui.table.setItem(0, i, QTableWidgetItem(text[i]))
else:
QMessageBox.about(self.ui,"warning","输入有误")
if method=="查找":
sentence=""
for i in range(hang_count):
for j in range(lie_count):
if text==self.ui.table.item(i,j).text():
for k in range(lie_count):
sentence+=self.ui.table.item(i,k).text()
sentence+='\t'
sentence+='\n'
QMessageBox.about(self.ui,"查询结果",sentence)
if method=="替换":
for i in range(hang_count):
if self.ui.table.item(i,1).text()==text[0]:
if text[1]=="班级":
self.ui.table.item(i,0).setText(text[2])
break
if text[1]=="姓名":
self.ui.table.item(i,1).setText(text[2])
break
if text[1]=="性别":
self.ui.table.item(i,2).setText(text[2])
break
if text[1]=="身高":
self.ui.table.item(i,3).setText(text[2])
break
if text[1]=="体重":
self.ui.table.item(i,4).setText(text[2])
break
else:
QMessageBox.about(self.ui,"warning","查无此人")
if method=="删除":
for i in range(hang_count):
for j in range(lie_count):
if text==self.ui.table.item(i,j).text():
self.ui.table.removeRow(i)
else:
QMessageBox.about(self.ui,"warning","无从下手")
self.ui.lineEdit.clear()
#---------------------------------------------------
#打开窗口,处理数据
#---------------------------------------------------
app = QApplication([])
stats = Stats()
stats.ui.show()
app.exec_()
23.1.24
"""
实现功能:1.存入(班级,姓名,性别,年龄,身高,体重)
2.删除
3.替换
4.查找
"""
#---------------------------------------------------
#导入文件
#---------------------------------------------------
from PySide2.QtWidgets import QApplication, QMessageBox
from PySide2.QtUiTools import QUiLoader
from PySide2.QtCore import QFile
from PySide2.QtWidgets import QTableWidgetItem
import time
class Stats:
def __init__(self):
#---------------------------------------------------
#读取窗口
#---------------------------------------------------
# 从文件中加载UI定义
struct=QFile('student.ui')
struct.open(QFile.ReadOnly)
struct.close
# 从 UI 定义中动态 创建一个相应的窗口对象
# 注意:里面的控件对象也成为窗口对象的属性了
# 比如 self.ui.button , self.ui.textEdit
self.ui = QUiLoader().load(struct)
self.ui.fasong.clicked.connect(self.handleCalc)
self.ui.lineEdit.returnPressed.connect(self.handleCalc)
def handleCalc(self):
method = self.ui.cbox.currentText()
text=self.ui.lineEdit.text()
hang_count = self.ui.table.rowCount()
lie_count = self.ui.table.columnCount()
if method=="存入":
if "-" in text:
text = [x for x in text.split('-')]
elif " " in text:
text = [x for x in text.split(' ')]
self.ui.table.insertRow(0)
for i in range(len(text)):
self.ui.table.setItem(0, i, QTableWidgetItem(text[i]))
self.ui.lineEdit.clear()
if method=="查找":
sentence=""
for i in range(hang_count):
for j in range(lie_count):
if text==self.ui.table.item(i,j).text():
for k in range(lie_count):
sentence+=self.ui.table.item(i,k).text()
sentence+='\t'
sentence+='\n'
self.ui.plaintext.setPlainText(sentence)
if method=="替换":
if "-" in text:
text = [x for x in text.split('-')]
elif " " in text:
text = [x for x in text.split(' ')]
for i in range(hang_count):
if self.ui.table.item(i,1).text()==text[0]:
if text[1]=="班级":
self.ui.table.item(i,0).setText(text[2])
break
if text[1]=="姓名":
self.ui.table.item(i,1).setText(text[2])
break
if text[1]=="性别":
self.ui.table.item(i,2).setText(text[2])
break
if text[1]=="身高":
self.ui.table.item(i,3).setText(text[2])
break
if text[1]=="体重":
self.ui.table.item(i,4).setText(text[2])
break
else:
self.ui.plaintext.setPlainText("查无此人")
if method=="删除":
for i in range(hang_count):
for j in range(lie_count):
if text==self.ui.table.item(i,j).text():
self.ui.table.removeRow(i)
self.ui.plaintext.clear()
else:
self.ui.plaintext.setPlainText("无从下手")
#---------------------------------------------------
#打开窗口,处理数据
#---------------------------------------------------
app = QApplication([])
stats = Stats()
stats.ui.show()
app.exec_()
界面展示