原代码:
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file '帝国时代登录界面.ui'
##
## Created by: Qt User Interface Compiler version 6.8.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QFrame, QLabel, QLineEdit,
QMainWindow, QPushButton, QSizePolicy, QStatusBar,
QWidget)
import res_rc
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(1000, 582)
MainWindow.setMinimumSize(QSize(0, 0))
MainWindow.setMaximumSize(QSize(1000, 582))
MainWindow.setStyleSheet(u"QMainWindow {\n"
" border-radius: 20px; \n"
" background-color: rgba(0, 0, 0, 0.8); \n"
"}")
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.centralwidget.setMinimumSize(QSize(1000, 562))
self.centralwidget.setMaximumSize(QSize(1000, 562))
self.centralwidget.setStyleSheet(u"Lay Out in a Vertical Layout\n"
"border-image: url(:/age_.gif);")
self.frame = QFrame(self.centralwidget)
self.frame.setObjectName(u"frame")
self.frame.setGeometry(QRect(0, 0, 1001, 571))
self.frame.setStyleSheet(u"QFrame {\n"
" border-radius: 20px;\n"
" background-color: rgba(0, 0, 0, 0);\n"
"}")
self.password = QLineEdit(self.frame)
self.password.setObjectName(u"password")
self.password.setGeometry(QRect(350, 380, 321, 31))
self.password.setStyleSheet(u" QLineEdit {\n"
" background-color: rgba(255, 255, 255, 0.3); /* \u534a\u900f\u660e */\n"
" border-width: 0 0 1px 0; /* \u5206\u522b\u8bbe\u7f6e\u4e0a\u3001\u53f3\u3001\u4e0b\u3001\u5de6\u8fb9\u6846\u7684\u5bbd\u5ea6\uff0c\u8fd9\u91cc\u4e0b\u8fb9\u6846\u4e3a1px\uff0c\u5176\u4ed6\u4e3a0 */\n"
" border-style: none none solid none; /* \u5206\u522b\u8bbe\u7f6e\u4e0a\u3001\u53f3\u3001\u4e0b\u3001\u5de6\u8fb9\u6846\u7684\u6837\u5f0f\uff0c\u8fd9\u91cc\u4e0b\u8fb9\u6846\u4e3a\u5b9e\u7ebf\uff0c\u5176\u4ed6\u4e3a\u65e0\u6837\u5f0f */\n"
" border-color: transparent transparent white transparent; /* \u5206\u522b\u8bbe\u7f6e\u4e0a\u3001\u53f3\u3001\u4e0b\u3001\u5de6\u8fb9\u6846\u7684\u989c\u8272\uff0c\u8fd9\u91cc\u4e0b\u8fb9\u6846\u4e3a\u767d\u8272\uff0c\u5176\u4ed6\u4e3a\u900f\u660e\u8272 */\n"
" color: white; /* \u5b57\u4f53\u989c\u8272\u767d\u8272 */\n"
" font-size: 15px; /* \u5b57\u4f53\u5927\u5c0f */\n"
" "
" padding: 5px;\n"
" }")
self.title_label = QLabel(self.frame)
self.title_label.setObjectName(u"title_label")
self.title_label.setGeometry(QRect(60, 90, 881, 151))
self.title_label.setStyleSheet(u"QLabel {\n"
" font-size: 100px;\n"
" font-weight: bold;\n"
" color: white;\n"
"}")
self.title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.age_gif = QLabel(self.frame)
self.age_gif.setObjectName(u"age_gif")
self.age_gif.setGeometry(QRect(0, 0, 1000, 562))
self.age_gif.setMinimumSize(QSize(1000, 562))
self.age_gif.setMaximumSize(QSize(1000, 562))
self.age_gif.setStyleSheet(u"border-radius: 20px;\n"
"background-color: rgba(0, 0, 0, 0.8);")
self.male_Button = QPushButton(self.frame)
self.male_Button.setObjectName(u"male_Button")
self.male_Button.setGeometry(QRect(530, 430, 51, 51))
self.male_Button.setStyleSheet(u"QPushButton {\n"
" border-image: url(:/Returnofrome_male_villager_icon.png);\n"
" border-repeat: no-repeat; \n"
" border-position: center; \n"
" border-size: 1px;\n"
" border-radius: 15px;\n"
" border: none; \n"
" padding: 0px; \n"
"}")
self.login_button = QPushButton(self.frame)
self.login_button.setObjectName(u"login_button")
self.login_button.setGeometry(QRect(350, 490, 151, 41))
self.login_button.setStyleSheet(u" QPushButton {\n"
" background: qlineargradient(\n"
" spread: pad, \n"
" x1: 0, y1: 0, x2: 1, y2: 0,\n"
" stop: 0 rgba(0, 0, 255, 0.8), stop: 1 rgba(255, 0, 0, 0.8)\n"
" );\n"
" color: white;\n"
" font-size: 18px;\n"
" border: 0px solid white;\n"
" border-radius: 10px;\n"
" padding: 10px;\n"
" }\n"
" QPushButton:hover {\n"
" background: qlineargradient(\n"
" spread: pad, \n"
" x1: 0, y1: 0, x2: 1, y2: 0, \n"
" stop: 0 rgba(173, 216, 230, 0.8), stop: 1 rgba(240, 128, 128, 0.8)\n"
" );\n"
" }")
self.female_Button = QPushButton(self.frame)
self.female_Button.setObjectName(u"female_Button")
self.female_Button.setGeometry(QRect(600, 430, 51, 51))
self.female_Button.setStyleSheet(u"QPushButton {\n"
" border-image: url(:/Returnofrome_female_villager_icon.png);\n"
" background-repeat: no-repeat; \n"
" background-position: center; \n"
" background-size: 1px;\n"
" border-radius: 15px;\n"
" border: none; \n"
" padding: 0px; \n"
"}")
self.username = QLineEdit(self.frame)
self.username.setObjectName(u"username")
self.username.setGeometry(QRect(350, 330, 321, 31))
self.username.setStyleSheet(u" QLineEdit {\n"
" background-color: rgba(255, 255, 255, 0.3); /* \u534a\u900f\u660e */\n"
" border-width: 0 0 1px 0; /* \u5206\u522b\u8bbe\u7f6e\u4e0a\u3001\u53f3\u3001\u4e0b\u3001\u5de6\u8fb9\u6846\u7684\u5bbd\u5ea6\uff0c\u8fd9\u91cc\u4e0b\u8fb9\u6846\u4e3a1px\uff0c\u5176\u4ed6\u4e3a0 */\n"
" border-style: none none solid none; /* \u5206\u522b\u8bbe\u7f6e\u4e0a\u3001\u53f3\u3001\u4e0b\u3001\u5de6\u8fb9\u6846\u7684\u6837\u5f0f\uff0c\u8fd9\u91cc\u4e0b\u8fb9\u6846\u4e3a\u5b9e\u7ebf\uff0c\u5176\u4ed6\u4e3a\u65e0\u6837\u5f0f */\n"
" border-color: transparent transparent white transparent; /* \u5206\u522b\u8bbe\u7f6e\u4e0a\u3001\u53f3\u3001\u4e0b\u3001\u5de6\u8fb9\u6846\u7684\u989c\u8272\uff0c\u8fd9\u91cc\u4e0b\u8fb9\u6846\u4e3a\u767d\u8272\uff0c\u5176\u4ed6\u4e3a\u900f\u660e\u8272 */\n"
" color: white; /* \u5b57\u4f53\u989c\u8272\u767d\u8272 */\n"
" font-size: 15px; /* \u5b57\u4f53\u5927\u5c0f */\n"
" "
" padding: 5px;\n"
" }")
self.Gender = QLabel(self.frame)
self.Gender.setObjectName(u"Gender")
self.Gender.setGeometry(QRect(350, 440, 211, 31))
font = QFont()
font.setFamilies([u"Microsoft YaHei UI"])
font.setKerning(True)
self.Gender.setFont(font)
self.Gender.setStyleSheet(u"font-size: 18px; color: white")
self.cancel_button = QPushButton(self.frame)
self.cancel_button.setObjectName(u"cancel_button")
self.cancel_button.setGeometry(QRect(520, 490, 151, 41))
self.cancel_button.setStyleSheet(u" QPushButton {\n"
" background: qlineargradient(\n"
" spread: pad, \n"
" x1: 0, y1: 0, x2: 1, y2: 0,\n"
" stop: 0 rgba(0, 0, 255, 0.8), stop: 1 rgba(255, 0, 0, 0.8)\n"
" );\n"
" color: white;\n"
" font-size: 18px;\n"
" border: 0px solid white;\n"
" border-radius: 10px;\n"
" padding: 10px;\n"
" }\n"
" QPushButton:hover {\n"
" background: qlineargradient(\n"
" spread: pad, \n"
" x1: 0, y1: 0, x2: 1, y2: 0, \n"
" stop: 0 rgba(173, 216, 230, 0.8), stop: 1 rgba(240, 128, 128, 0.8)\n"
" );\n"
" }")
self.age_gif.raise_()
self.Gender.raise_()
self.password.raise_()
self.title_label.raise_()
self.male_Button.raise_()
self.login_button.raise_()
self.female_Button.raise_()
self.username.raise_()
self.cancel_button.raise_()
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QStatusBar(MainWindow)
self.statusbar.setObjectName(u"statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u5e1d\u56fd\u65f6\u4ee3 - \u767b\u5f55", None))
self.password.setText("")
self.password.setPlaceholderText(QCoreApplication.translate("MainWindow", u"\u8bf7\u8f93\u5165\u5bc6\u7801", None))
self.title_label.setText(QCoreApplication.translate("MainWindow", u"\u6b22\u8fce\u6765\u5230\u5e1d\u56fd\u65f6\u4ee3", None))
self.age_gif.setText(QCoreApplication.translate("MainWindow", u"<html><head/><body><p><img src=\":/age_.gif\"/></p></body></html>", None))
self.male_Button.setText("")
self.login_button.setText(QCoreApplication.translate("MainWindow", u"\u767b\u5f55", None))
#if QT_CONFIG(tooltip)
self.female_Button.setToolTip(QCoreApplication.translate("MainWindow", u"<html><head/><body><p><br/></p></body></html>", None))
#endif // QT_CONFIG(tooltip)
self.female_Button.setText(QCoreApplication.translate("MainWindow", u"\u5973", None))
self.username.setText("")
self.username.setPlaceholderText(QCoreApplication.translate("MainWindow", u"\u8bf7\u8f93\u5165\u7528\u6237\u540d", None))
self.Gender.setText(QCoreApplication.translate("MainWindow", u"\u9009\u62e9\u6027\u522b: \u672a\u9009\u62e9", None))
self.cancel_button.setText(QCoreApplication.translate("MainWindow", u"\u53d6\u6d88", None))
# retranslateUi
import sys
import os
import subprocess
from PySide6.QtWidgets import QApplication, QMainWindow, QMessageBox, QLineEdit, QPushButton, QLabel, QVBoxLayout, QWidget
from PySide6.QtCore import Qt, Slot
from PySide6.QtGui import QIcon, QMovie
from login_ui import Ui_MainWindow # 导入 UI 文件
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# 初始化 UI
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# 设置无边框窗口和圆角
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
# 设置应用图标
self.setWindowIcon(QIcon("ReturnRome-AoEIcon.png"))
# 使用 QMovie 播放背景动图
self.movie = QMovie(":/age_.gif") # 确保资源路径正确
self.ui.age_gif.setMovie(self.movie)
self.movie.start()
# 设置登录按钮的点击事件
self.ui.login_button.clicked.connect(self.handle_login)
# 设置 male 和 female 按钮点击事件
self.ui.male_Button.clicked.connect(self.select_male)
self.ui.female_Button.clicked.connect(self.select_female)
# 设置取消按钮点击事件
self.ui.cancel_button.clicked.connect(self.close) # 关闭窗口
# 创建用户名和密码输入框
self.username_input = self.ui.username # 使用 UI 中的 username 输入框
self.password_input = self.ui.password # 使用 UI 中的 password 输入框
# 设置密码框为密码输入模式
self.password_input.setEchoMode(QLineEdit.Password)
@Slot()
def handle_login(self):
"""处理登录事件"""
username = self.username_input.text()
password = self.password_input.text()
# 验证用户名和密码
if username == "admin" and password == "123456":
# 登录成功,关闭当前界面并启动游戏
QMessageBox.information(self, "登录成功", "欢迎进入帝国时代!")
self.close()
# 启动游戏程序
game_path = r"D:\steam\steamapps\common\AoEDE\AoEDE_s.exe"
if os.path.exists(game_path): # 检查文件路径是否存在
subprocess.Popen(game_path) # 启动游戏
else:
QMessageBox.warning(self, "错误", "游戏文件未找到!")
else:
# 登录失败,显示错误信息并清空输入框
QMessageBox.warning(self, "登录失败", "用户名或密码错误!")
self.username_input.clear()
self.password_input.clear()
def select_male(self):
"""选择男性按钮事件"""
self.ui.Gender.setText("选择性别: 男")
def select_female(self):
"""选择女性按钮事件"""
self.ui.Gender.setText("选择性别: 女")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())