import sys
from PySide6.QtCore import Qt, QTimer
from PySide6.QtGui import QFont, QColor, QPalette, QPixmap, QPainter, QPen, QBrush, QLinearGradient, QPainterPath
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QProgressBar, QLineEdit, QPushButton, \
QMessageBox, QHBoxLayout
class WelcomeWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('欢迎界面')
self.setGeometry(300, 100, 1400, 900)
# 设置字体
font = QFont('隶书', 40, QFont.Bold)
# 创建标签显示欢迎词
self.welcome_label = QLabel(self)
self.welcome_label.setText('欢迎')
self.welcome_label.setFont(font)
self.welcome_label.move(700, 400)
self.welcome_label.setFixedSize(200, 50)
# 设置背景图片
background_label = QLabel(self)
background_image = QPixmap('路径/到/你的/背景图片')
background_label.setPixmap(background_image.scaled(self.size()))
background_label.resize(self.size())
# 创建进度条
self.progress_bar = QProgressBar(self)
self.progress_bar.setGeometry(450, 830, 500, 30)
self.progress_bar.setTextVisible(True)
self.progress_bar.setStyleSheet("""
QProgressBar::chunk {
background-color: #2196F3;
width: 10px;
}
""")
# 设置定时器每秒更新进度条
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_progress)
self.timer.start(50)
def update_progress(self):
value = self.progress_bar.value()
if value < 100:
value += 1
self.progress_bar.setValue(value)
else:
self.timer.stop()
self.show_login_window()
def show_login_window(self):
login_window = QWidget()
login_window.setWindowTitle('用户登录')
# 创建用户名和密码输入框
username_label = QLabel('用户名:', login_window)
username_label.setFont(QFont('隶书', 20))
username_entry = QLineEdit(login_window)
password_label = QLabel('密码:', login_window)
password_label.setFont(QFont('隶书', 20))
password_entry = QLineEdit(login_window)
password_entry.setEchoMode(QLineEdit.Password)
# 登录按钮功能
def login():
username = username_entry.text()
password = password_entry.text()
if username == 'admin' and password == '123456':
QMessageBox.information(login_window, '提示', '登录成功!')
login_window.close()
self.open_main_window()
else:
QMessageBox.critical(login_window, '错误', '用户名或密码错误!')
password_entry.clear()
login_button = QPushButton('登录', login_window)
login_button.setFont(QFont('隶书', 20))
login_button.clicked.connect(login)
# 使用垂直布局
layout = QVBoxLayout()
layout.addWidget(username_label)
layout.addWidget(username_entry)
layout.addWidget(password_label)
layout.addWidget(password_entry)
layout.addWidget(login_button)
login_window.setLayout(layout)
login_window.setGeometry(650, 450, 400, 300)
login_window.show()
def open_main_window(self):
self.hide() # 隐藏欢迎窗体
main_window = QWidget()
main_window.setWindowTitle('主窗体')
main_window.setGeometry(100, 100, 600, 600)
# 创建按钮
buttons_layout = QHBoxLayout()
for i in range(12):
button = QPushButton(f'按钮{i+1}')
buttons_layout.addWidget(button)
main_layout = QVBoxLayout()
main_layout.addLayout(buttons_layout)
main_window.setLayout(main_layout)
main_window.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
welcome_window = WelcomeWindow()
welcome_window.show()
sys.exit(app.exec())