pyqt5的小案例
做一下记录,免得以后找不到源码
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '.\学生信息查询1.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
import pandas as pd
import os,sys,time
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
mainWindow.setObjectName("mainWindow")
mainWindow.resize(515, 326)
self.centralwidget = QtWidgets.QWidget(mainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.match_it = QtWidgets.QPushButton(self.centralwidget)
self.match_it.setObjectName("match_it")
self.match_it.clicked.connect(self.read_excle)
self.gridLayout.addWidget(self.match_it, 3, 2, 1, 1)
self.sutdentname = QtWidgets.QLabel(self.centralwidget)
self.sutdentname.setObjectName("sutdentname")
self.gridLayout.addWidget(self.sutdentname, 0, 0, 1, 1)
self.student_name = QtWidgets.QLineEdit(self.centralwidget)
self.student_name.setObjectName("student_name")
self.gridLayout.addWidget(self.student_name, 3, 0, 1, 1)
self.current_time = QtWidgets.QLabel(self.centralwidget)
self.current_time.setObjectName("current_time")
self.gridLayout.addWidget(self.current_time, 7, 0, 1, 1)
self.sutdent_class = QtWidgets.QLineEdit(self.centralwidget)
self.sutdent_class.setObjectName("sutdent_class")
self.gridLayout.addWidget(self.sutdent_class, 3, 1, 1, 1)
self.current_classyear = QtWidgets.QLabel(self.centralwidget)
self.current_classyear.setObjectName("current_classyear")
self.gridLayout.addWidget(self.current_classyear, 7, 1, 1, 1)
self.studentclass = QtWidgets.QLabel(self.centralwidget)
self.studentclass.setObjectName("studentclass")
self.gridLayout.addWidget(self.studentclass, 0, 1, 1, 1)
self.infowindow = QtWidgets.QTextBrowser(self.centralwidget)
self.infowindow.setObjectName("infowindow")
self.gridLayout.addWidget(self.infowindow, 8, 0, 1, 3)
mainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(mainWindow)
QtCore.QMetaObject.connectSlotsByName(mainWindow)
def retranslateUi(self, mainWindow):
_translate = QtCore.QCoreApplication.translate
mainWindow.setWindowTitle(_translate("mainWindow", "学生信息查询V1.2 作者:ArnoLIN 联系方式:GK_LinNa"))
self.match_it.setText(_translate("mainWindow", "查找"))
self.sutdentname.setText(_translate("mainWindow", "学生姓名"))
self.current_time.setText(_translate("mainWindow", "当前时间:XXXX-XX-XX XX:XX:XX"))
self.current_classyear.setText(_translate("mainWindow", "当前学年"))
self.studentclass.setText(_translate("mainWindow", "学生班级"))
def read_excle(self):
data = {'一':0,'二':1,'三':2,'四':3,'五':4,'六':5,'七':6,'八':7,'九':8}
self.infowindow.clear()
name = self.student_name.text()
name = name.split('\n')
print(name)
file = os.listdir('./')
for i in file:
class_1 = self.sutdent_class.text()
if 'xls' in i:
excel = pd.read_excel(f'./{i}')
name_list = excel['姓名'].tolist()
class_year = excel['年级'].tolist()
class_list = excel['班级'].tolist()
student_id = excel['学籍号'].tolist()
if '级' in class_1:
class_1 = class_1.split(' ')
print(class_1)
for n in range(len(name_list)):
if int(time.strftime('%m'))<=8 and int(time.strftime('%d'))<=31:
now_year = int(time.strftime('%Y')) - 1
else:
now_year = int(time.strftime('%Y'))
# print(class_1[0])
# print(class_1[-1])
if class_1[0] in class_year[n] and class_1[-1] in class_list[n]and name == '':
if class_year[n][0] in data:
now_year = now_year - data[class_year[n][0]]
message = name_list[n]+' '+class_year[n]+class_list[n]+' '+str(now_year)+'级'+' '+student_id[n]
self.infowindow.append(message)
elif class_1[0] in class_year[n] and class_1[-1] == ''and name == '':
if class_year[n][0] in data:
now_year = now_year - data[class_year[n][0]]
message = name_list[n]+' '+class_year[n]+class_list[n]+' '+str(now_year)+'级'+' '+student_id[n]
self.infowindow.append(message)
elif class_1[0] in class_year[n] and class_1[-1] in class_list[n] and name[0] in name_list[n]:
if class_year[n][0] in data:
now_year = now_year - data[class_year[n][0]]
message = name_list[n]+' '+class_year[n]+class_list[n]+' '+str(now_year)+'级'+' '+student_id[n]
self.infowindow.append(message)
elif class_1[0] in class_year[n] and class_1[-1] == ''and name[0] in name_list[n]:
if class_year[n][0] in data:
now_year = now_year - data[class_year[n][0]]
message = name_list[n]+' '+class_year[n]+class_list[n]+' '+str(now_year)+'级'+' '+student_id[n]
self.infowindow.append(message)
for m in name:
print(m)
print(type(class_1))
if m == '':
break
for x in range(len(name_list)):
if m in name_list[x]and class_1 == '':
if int(time.strftime('%m'))<=8 and int(time.strftime('%d'))<=31:
now_year = int(time.strftime('%Y')) - 1
else:
now_year = int(time.strftime('%Y'))
if class_year[x][0] in data:
now_year = now_year - data[class_year[x][0]]
# print(now_year)
message = name_list[x]+' '+class_year[x]+class_list[x]+' '+str(now_year)+'级'+' '+student_id[x]
# print(message)
self.infowindow.append(message)
def current_classyear_update(self):
if int(time.strftime('%m'))<=8 and int(time.strftime('%d'))<=31:
now_year = int(time.strftime('%Y')) - 1
else:
now_year = int(time.strftime('%Y'))
self.current_classyear.setText(f'当前学年:{now_year}级')
def time_update(self,msg):
self.current_time.setText(msg)
def start_update(self):
self.thread = None
self.thread = runthread()
self.thread.signal.connect(self.time_update)
self.thread.start()
class runthread(QtCore.QThread):
signal = QtCore.pyqtSignal(str)
def __init__(self):
super(runthread,self).__init__()
def __del__(self):
self.wait()
def run(self):
global current_time
while True:
current_time = time.strftime('当前时间:%Y-%m-%d %H:%M:%S')
self.signal.emit(current_time)
self.sleep(1)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
mainwindow = QtWidgets.QMainWindow()
ui = Ui_mainWindow()
ui.setupUi(mainwindow)
ui.current_classyear_update()
ui.start_update()
mainwindow.show()
sys.exit(app.exec_())
笔记完毕