from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1440, 900)
Form.setMinimumSize(QtCore.QSize(1440, 900))
Form.setMaximumSize(QtCore.QSize(1440, 900))
Form.setStyleSheet("background-color: rgb(135, 206, 235);")
# 设置垂直布局
self.verticalLayoutWidget = QtWidgets.QWidget(parent=Form)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(470, 140, 461, 251))
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setSpacing(5)
self.verticalLayout.setObjectName("verticalLayout")
# 设置label
self.label = QtWidgets.QLabel(parent=self.verticalLayoutWidget)
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(55)
self.label.setFont(font)
self.label.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.label_2 = QtWidgets.QLabel(parent=self.verticalLayoutWidget)
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(60)
self.label_2.setFont(font)
self.label_2.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.label_2.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.label_2.setObjectName("label_2")
self.verticalLayout.addWidget(self.label_2)
# 设置第二个垂直布局
self.verticalLayoutWidget_2 = QtWidgets.QWidget(parent=Form)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(490, 469, 411, 166))
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.label_3 = QtWidgets.QLabel(parent=self.verticalLayoutWidget_2)
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(25)
self.label_3.setFont(font)
self.label_3.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.label_3.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.label_3.setObjectName("label_3")
self.verticalLayout_2.addWidget(self.label_3)
self.lineEdit = QtWidgets.QLineEdit(parent=self.verticalLayoutWidget_2)
self.lineEdit.setMaximumSize(QtCore.QSize(16777215, 35))
self.lineEdit.setStyleSheet("background-color: rgb(255, 255, 255);")
self.lineEdit.setObjectName("lineEdit")
self.verticalLayout_2.addWidget(self.lineEdit)
self.label_4 = QtWidgets.QLabel(parent=self.verticalLayoutWidget_2)
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(25)
self.label_4.setFont(font)
self.label_4.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.label_4.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.label_4.setObjectName("label_4")
self.verticalLayout_2.addWidget(self.label_4)
self.lineEdit_2 = QtWidgets.QLineEdit(parent=self.verticalLayoutWidget_2)
self.lineEdit_2.setMaximumSize(QtCore.QSize(16777215, 35))
self.lineEdit_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.lineEdit_2.setObjectName("lineEdit_2")
self.verticalLayout_2.addWidget(self.lineEdit_2)
# 设置第三个垂直布局
self.verticalLayoutWidget_3 = QtWidgets.QWidget(parent=Form)
self.verticalLayoutWidget_3.setGeometry(QtCore.QRect(1260, 690, 160, 119))
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_3)
self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.pushButton_3 = QtWidgets.QPushButton(parent=self.verticalLayoutWidget_3)
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(20)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
self.verticalLayout_3.addWidget(self.pushButton_3)
self.pushButton_4 = QtWidgets.QPushButton(parent=self.verticalLayoutWidget_3)
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(20)
self.pushButton_4.setFont(font)
self.pushButton_4.setObjectName("pushButton_4")
self.verticalLayout_3.addWidget(self.pushButton_4)
self.pushButton_2 = QtWidgets.QPushButton(parent=self.verticalLayoutWidget_3)
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(20)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.verticalLayout_3.addWidget(self.pushButton_2)
self.progressBar = QtWidgets.QProgressBar(parent=Form)
self.progressBar.setGeometry(QtCore.QRect(370, 830, 641, 21))
self.progressBar.setProperty("value", 0) # 设置初始value为0
self.progressBar.setObjectName("progressBar")
self.pushButton = QtWidgets.QPushButton(parent=Form)
self.pushButton.setGeometry(QtCore.QRect(610, 670, 171, 35))
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(20)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.label_5 = QtWidgets.QLabel(parent=Form)
self.label_5.setGeometry(QtCore.QRect(480, 780, 409, 38))
font = QtGui.QFont()
font.setFamily("隶书")
font.setPointSize(20)
self.label_5.setFont(font)
self.label_5.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.label_5.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.label_5.setObjectName("label_5")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "HuanYing"))
self.label.setText(_translate("Form", "欢 迎 使 用"))
self.label_2.setText(_translate("Form", "本 系 统"))
self.label_3.setText(_translate("Form", "用户名"))
self.label_4.setText(_translate("Form", "密码"))
self.label_5.setText(_translate("Form", "载入中,请稍候..."))
self.pushButton_3.setText(_translate("Form", "选项调整"))
self.pushButton_4.setText(_translate("Form", "帮助"))
self.pushButton_2.setText(_translate("Form", "退出"))
self.pushButton.setText(_translate("Form", "登录"))
class MyForm(QtWidgets.QWidget, Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.centerWindow()
self.setBgColor()
self.startMusic()
self.connectSignals()
def centerWindow(self):
# 窗体居中
desktop = QtWidgets.QApplication.desktop()
screenRect = desktop.screenGeometry()
windowRect = self.geometry()
x = (screenRect.width() - windowRect.width()) // 2
y = (screenRect.height() - windowRect.height()) // 2
self.move(x, y)
# label_5垂直居中对齐
label_height = self.label_5.height()
label_y = y + (windowRect.height() - label_height) // 2
self.label_5.move(self.label_5.x(), label_y)
# label_4垂直居中对齐
label_4_height = self.label_4.height()
label_4_y = y + (windowRect.height() - label_4_height) // 2
self.label_4.move(self.label_4.x(), label_4_y)
def setBgColor(self):
# 设置背景颜色
self.setStyleSheet("background-color: rgb(255, 255, 255);")
def startMusic(self):
# 启动音乐
# 加入启动音乐的代码
def connectSignals(self):
# 连接信号和槽
self.pushButton.clicked.connect(self.checkLogin)
def checkLogin(self):
# 检查用户名和密码
username = self.lineEdit.text()
password = self.lineEdit_2.text()
# 模拟检查逻辑
if username == "admin" and password == "123456":
self.label_5.show()
self.progressBar.setValue(0)
self.progressBar.show()
self.progressBar.setMaximum(100)
self.progressBar.scrollToCenter()
self.progressBar.startAnimation()
else:
self.showMessageBox()
def showMessageBox(self):
# 显示错误提示框
msgBox = QtWidgets.QMessageBox()
msgBox.setText("用户名或密码不正确,请重新输入!")
msgBox.setWindowTitle("错误")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icon.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
msgBox.setWindowIcon(icon)
msgBox.exec()
def keyPressEvent(self, event):
# 键盘事件
if event.key() == QtCore.Qt.Key.Key_Escape:
self.close()
def closeEvent(self, event):
# 窗体关闭事件
# 判断滚动条是否达到 100%
if self.progressBar.value() == 100:
# 打开主窗口
mainWindow = MainWindow()
mainWindow.show()
else:
# 关闭程序
event.accept()
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
# 主窗口的初始化代码
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
myForm = MyForm()
myForm.show()
sys.exit(app.exec())
请注意,音乐播放的部分需要根据您所使用的音乐播放库进行相应的调整,这里只是示例代码。另外,您还需要提供一张名为"icon.png"的图标文件,并将其与脚本文件放在同一目录下。