怪物奇妙物语

宇宙无敌超级美少男的怪物奇妙物语

首页 新随笔 联系 管理
  822 随笔 :: 0 文章 :: 2 评论 :: 16万 阅读

pyqt_login-master/main.py

import sys
from PyQt6 import QtGui, QtWidgets
from PyQt6.QtWidgets import QMainWindow, QMessageBox
from Windows import login
user_icon = "assets/favicon.ico"
users = {"user": "admin123"}
class Login(QMainWindow, login.MainWindow):
"""Handles the login window events"""
def __init__(self, *args, **kwargs):
QMainWindow.__init__(self, *args, **kwargs)
self.set_ui(self)
self.login_button.clicked.connect(self.check) # Connects the button to an action
self.save_button.clicked.connect(self.check_save)
def check(self):
"""Checks if the given credentials are inside the database, in this case, a dictionary"""
if self.user_input.text() in users and self.password_input.text() == users[self.user_input.text()]:
msg = QMessageBox()
msg.setWindowIcon(QtGui.QIcon(user_icon))
msg.setText("Successfull!")
msg.setInformativeText("The credentials are correct.")
msg.setWindowTitle("login")
msg.exec()
else:
msg = QMessageBox()
msg.setWindowIcon(QtGui.QIcon(user_icon))
msg.setText("Error!")
msg.setInformativeText("The credentials are incorrect.")
msg.setWindowTitle("login")
msg.exec()
def check_save(self):
msg = QMessageBox()
msg.setWindowIcon(QtGui.QIcon(user_icon))
msg.setText("密码已更新")
msg.setInformativeText("!!!密码加密保存成功!!!")
msg.setWindowTitle("密码更新")
msg.exec()
def check_scorll_area(self):
print("")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
app.setStyleSheet(open("assets/style.css", encoding="utf-8").read())
login_gui = Login()
login_gui.show()
sys.exit(app.exec())

pyqt_login-master/Windows/login.py.o1.txt

from PyQt6 import QtCore, QtGui, QtWidgets
user_icon = "assets/favicon.ico"
class MainWindow(object):
"""Login window definition"""
def set_ui(self, login_window):
"""_summary_
Args:
login_window (_type_): _description_
"""
login_window.setObjectName("login_window")
login_window.resize(291, 160)
login_window.setTabShape(QtWidgets.QTabWidget.TabShape.Rounded)
login_window.setWindowIcon(QtGui.QIcon(user_icon))
self.centralwidget = QtWidgets.QWidget(login_window)
self.centralwidget.setObjectName("centralwidget")
self.login_button = QtWidgets.QPushButton(self.centralwidget)
self.login_button.setGeometry(QtCore.QRect(10, 10, 271, 31))
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.login_button.setFont(font)
self.login_button.setObjectName("login_button")
self.save_button = QtWidgets.QPushButton(self.centralwidget)
self.save_button.setGeometry(QtCore.QRect(10, 110, 271, 31))
self.save_button.setObjectName("save_button")
self.user_input = QtWidgets.QLineEdit(self.centralwidget)
self.user_input.setGeometry(QtCore.QRect(10, 50, 271, 25))
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.user_input.setFont(font)
self.user_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.user_input.setObjectName("user_input")
self.password_input = QtWidgets.QLineEdit(self.centralwidget)
self.password_input.setGeometry(QtCore.QRect(10, 80, 271, 25))
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.password_input.setFont(font)
self.password_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_input.setObjectName("password_input")
login_window.setCentralWidget(self.centralwidget)
self.retranslate_ui(login_window)
QtCore.QMetaObject.connectSlotsByName(login_window)
def retranslate_ui(self, login_window):
translate = QtCore.QCoreApplication.translate
login_window.setWindowTitle(translate("login_window", "AGV"))
self.login_button.setText(translate("login_window", "登录AGV"))
self.save_button.setText(translate("login_window", "保存密码"))
self.user_input.setPlaceholderText(translate("login_window", "请输入账号"))
self.password_input.setPlaceholderText(translate("login_window", "请输入密码"))

pyqt_login-master/Windows/__init__.py

pyqt_login-master/Windows/login.py.05.txt

from PyQt6 import QtCore, QtGui, QtWidgets
user_icon = "assets/favicon.ico"
class MainWindow(object):
"""Login window definition"""
def set_ui(self, login_window):
"""_summary_
Args:
login_window (_type_): _description_
"""
login_window.setObjectName("login_window")
login_window.resize(300, 500)
login_window.setTabShape(QtWidgets.QTabWidget.TabShape.Rounded)
login_window.setWindowIcon(QtGui.QIcon(user_icon))
self.centralwidget = QtWidgets.QWidget(login_window)
self.centralwidget.setObjectName("centralwidget")
grid_layout = QtWidgets.QGridLayout(self.centralwidget)
self.user_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
self.user_input.setFont(font)
self.user_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.user_input.setObjectName("user_input")
grid_layout.addWidget(self.user_input, 0, 0, 1, 1)
self.password_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
self.password_input.setFont(font)
self.password_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_input.setObjectName("password_input")
self.password_input.setGeometry(QtCore.QRect(10, 10, 271, 31))
grid_layout.addWidget(self.password_input, 0, 1, 1, 1)
self.save_button = QtWidgets.QPushButton()
self.save_button.setObjectName("save_button")
grid_layout.addWidget(self.save_button, 0, 2, 1, 1)
self.login_button = QtWidgets.QPushButton()
font = QtGui.QFont()
self.login_button.setFont(font)
self.login_button.setObjectName("login_button")
# def addLayout(self, a0: QLayout, row: int, column: int, rowSpan: int, columnSpan: int, alignment: QtCore.Qt.AlignmentFlag = ...) -> None: ...
grid_layout.addWidget(self.login_button, 1, 0, 1, 3)
login_window.setCentralWidget(self.centralwidget)
self.retranslate_ui(login_window)
QtCore.QMetaObject.connectSlotsByName(login_window)
def retranslate_ui(self, login_window):
translate = QtCore.QCoreApplication.translate
login_window.setWindowTitle(translate("login_window", "AGV"))
self.login_button.setText(translate("login_window", "登录AGV"))
self.save_button.setText(translate("login_window", "保存密码"))
self.user_input.setPlaceholderText(translate("login_window", "请输入账号"))
self.password_input.setPlaceholderText(translate("login_window", "请输入密码"))

pyqt_login-master/Windows/login.py

from PyQt6 import QtCore, QtGui, QtWidgets
user_icon = "assets/favicon.ico"
class MainWindow(object):
"""Login window definition"""
def set_ui(self, login_window):
"""_summary_
Args:
login_window (_type_): _description_
"""
login_window.setObjectName("login_window")
login_window.resize(500, 500)
login_window.setTabShape(QtWidgets.QTabWidget.TabShape.Rounded)
login_window.setWindowIcon(QtGui.QIcon(user_icon))
login_window.setWindowTitle("一键登录")
self.centralwidget = QtWidgets.QWidget(login_window)
self.centralwidget.setObjectName("centralwidget")
grid_layout = QtWidgets.QGridLayout(self.centralwidget)
self.user_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
self.user_input.setFont(font)
self.user_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.user_input.setObjectName("user_input")
self.user_input.setPlaceholderText("请输入账号")
grid_layout.addWidget(self.user_input, 0, 0, 1, 1)
self.password_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
self.password_input.setFont(font)
self.password_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_input.setObjectName("password_input")
self.password_input.setPlaceholderText("请输入密码")
grid_layout.addWidget(self.password_input, 0, 1, 1, 1)
self.save_button = QtWidgets.QPushButton()
self.save_button.setObjectName("save_button")
self.save_button.setText("保存密码")
grid_layout.addWidget(self.save_button, 0, 2, 1, 1)
self.login_button = QtWidgets.QPushButton()
font = QtGui.QFont()
self.login_button.setFont(font)
self.login_button.setObjectName("login_button")
self.login_button.setText("登录AGV")
grid_layout.addWidget(self.login_button, 1, 0, 1, 3)
self.scroll_area = QtWidgets.QScrollArea()
self.scroll_area.setWidgetResizable(True)
self.scroll_content = QtWidgets.QWidget()
self.scroll_layout = QtWidgets.QVBoxLayout(self.scroll_content)
self.add_buttons_to_scroll_area(self.scroll_layout)
self.scroll_area.setWidget(self.scroll_content)
self.scroll_area.setStyleSheet("background-color: #d3efff") # 设置背景颜色
grid_layout.addWidget(self.scroll_area, 2, 0, 1, 3)
login_window.setCentralWidget(self.centralwidget)
QtCore.QMetaObject.connectSlotsByName(login_window)
def add_buttons_to_scroll_area(self, layout):
"""添加更多按钮到滚动区域"""
for i in range(20):
button = QtWidgets.QPushButton(f"button_{i}")
button.setObjectName(f"button_{i}")
button.setStyleSheet("text-align: left;padding-left:5px;") # 设置文本对齐方式为左对齐
button.clicked.connect(self.button_clicked)
layout.addWidget(button)
def button_clicked(self):
sender = self.sender()
button_text = sender.text()
print(f"Button clicked: {button_text}")

pyqt_login-master/Windows/login.py.04.txt

from PyQt6 import QtCore, QtGui, QtWidgets
user_icon = "assets/favicon.ico"
class MainWindow(object):
"""Login window definition"""
def set_ui(self, login_window):
"""_summary_
Args:
login_window (_type_): _description_
"""
login_window.setObjectName("login_window")
login_window.resize(291, 160)
login_window.setTabShape(QtWidgets.QTabWidget.TabShape.Rounded)
login_window.setWindowIcon(QtGui.QIcon(user_icon))
self.centralwidget = QtWidgets.QWidget(login_window)
self.centralwidget.setObjectName("centralwidget")
vertical_layout = QtWidgets.QVBoxLayout(self.centralwidget)
horizontal_layout = QtWidgets.QHBoxLayout()
vertical_layout.addLayout(horizontal_layout)
self.login_button = QtWidgets.QPushButton()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.login_button.setFont(font)
self.login_button.setObjectName("login_button")
horizontal_layout.addWidget(self.login_button)
self.save_button = QtWidgets.QPushButton()
self.save_button.setObjectName("save_button")
horizontal_layout.addWidget(self.save_button)
self.user_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.user_input.setFont(font)
self.user_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.user_input.setObjectName("user_input")
vertical_layout.addWidget(self.user_input)
self.password_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.password_input.setFont(font)
self.password_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_input.setObjectName("password_input")
vertical_layout.addWidget(self.password_input)
login_window.setCentralWidget(self.centralwidget)
self.retranslate_ui(login_window)
QtCore.QMetaObject.connectSlotsByName(login_window)
def retranslate_ui(self, login_window):
translate = QtCore.QCoreApplication.translate
login_window.setWindowTitle(translate("login_window", "AGV"))
self.login_button.setText(translate("login_window", "登录AGV"))
self.save_button.setText(translate("login_window", "保存密码"))
self.user_input.setPlaceholderText(translate("login_window", "请输入账号"))
self.password_input.setPlaceholderText(translate("login_window", "请输入密码"))

pyqt_login-master/Windows/login.py.06.txt

from PyQt6 import QtCore, QtGui, QtWidgets
user_icon = "assets/favicon.ico"
class MainWindow(object):
"""Login window definition"""
def set_ui(self, login_window):
"""_summary_
Args:
login_window (_type_): _description_
"""
login_window.setObjectName("login_window")
login_window.resize(291, 400)
login_window.setTabShape(QtWidgets.QTabWidget.TabShape.Rounded)
login_window.setWindowIcon(QtGui.QIcon(user_icon))
self.centralwidget = QtWidgets.QWidget(login_window)
self.centralwidget.setObjectName("centralwidget")
grid_layout = QtWidgets.QGridLayout(self.centralwidget)
self.scroll_area = QtWidgets.QScrollArea(self.centralwidget)
self.scroll_area.setWidgetResizable(True)
scroll_content = QtWidgets.QWidget()
scroll_layout = QtWidgets.QVBoxLayout(scroll_content)
self.login_button = QtWidgets.QPushButton()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.login_button.setFont(font)
self.login_button.setObjectName("login_button")
scroll_layout.addWidget(self.login_button)
self.user_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.user_input.setFont(font)
self.user_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.user_input.setObjectName("user_input")
scroll_layout.addWidget(self.user_input)
self.password_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.password_input.setFont(font)
self.password_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_input.setObjectName("password_input")
scroll_layout.addWidget(self.password_input)
self.save_button = QtWidgets.QPushButton()
self.save_button.setObjectName("save_button")
scroll_layout.addWidget(self.save_button)
self.add_buttons_to_scroll_area(scroll_layout) # 添加更多按钮到滚动区域
self.scroll_area.setWidget(scroll_content)
grid_layout.addWidget(self.scroll_area, 0, 0, 1, 3)
login_window.setCentralWidget(self.centralwidget)
self.retranslate_ui(login_window)
QtCore.QMetaObject.connectSlotsByName(login_window)
def retranslate_ui(self, login_window):
translate = QtCore.QCoreApplication.translate
login_window.setWindowTitle(translate("login_window", "AGV"))
self.login_button.setText(translate("login_window", "登录AGV"))
self.save_button.setText(translate("login_window", "保存密码"))
self.user_input.setPlaceholderText(translate("login_window", "请输入账号"))
self.password_input.setPlaceholderText(translate("login_window", "请输入密码"))
def add_buttons_to_scroll_area(self, layout):
"""添加更多按钮到滚动区域"""
for i in range(10):
button = QtWidgets.QPushButton(f"Button {i+1}")
layout.addWidget(button)
# app = QtWidgets.QApplication([])
# window = QtWidgets.QMainWindow()
# ui = MainWindow()
# ui.set_ui(window)
# window.show()
# app.exec()

pyqt_login-master/Windows/login.py.03.txt

from PyQt6 import QtCore, QtGui, QtWidgets
user_icon = "assets/favicon.ico"
class MainWindow(object):
"""Login window definition"""
def set_ui(self, login_window):
"""_summary_
Args:
login_window (_type_): _description_
"""
login_window.setObjectName("login_window")
login_window.resize(291, 160)
login_window.setTabShape(QtWidgets.QTabWidget.TabShape.Rounded)
login_window.setWindowIcon(QtGui.QIcon(user_icon))
self.centralwidget = QtWidgets.QWidget(login_window)
self.centralwidget.setObjectName("centralwidget")
layout = QtWidgets.QVBoxLayout(self.centralwidget)
self.login_button = QtWidgets.QPushButton()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.login_button.setFont(font)
self.login_button.setObjectName("login_button")
layout.addWidget(self.login_button)
self.save_button = QtWidgets.QPushButton()
self.save_button.setObjectName("save_button")
layout.addWidget(self.save_button)
self.user_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.user_input.setFont(font)
self.user_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.user_input.setObjectName("user_input")
layout.addWidget(self.user_input)
self.password_input = QtWidgets.QLineEdit()
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.password_input.setFont(font)
self.password_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_input.setObjectName("password_input")
layout.addWidget(self.password_input)
login_window.setCentralWidget(self.centralwidget)
self.retranslate_ui(login_window)
QtCore.QMetaObject.connectSlotsByName(login_window)
def retranslate_ui(self, login_window):
translate = QtCore.QCoreApplication.translate
login_window.setWindowTitle(translate("login_window", "AGV"))
self.login_button.setText(translate("login_window", "登录AGV"))
self.save_button.setText(translate("login_window", "保存密码"))
self.user_input.setPlaceholderText(translate("login_window", "请输入账号"))
self.password_input.setPlaceholderText(translate("login_window", "请输入密码"))

pyqt_login-master/Windows/login.py.02.txt

from PyQt6 import QtCore, QtGui, QtWidgets
user_icon = "assets/favicon.ico"
class MainWindow(object):
"""Login window definition"""
def set_ui(self, login_window):
"""_summary_
Args:
login_window (_type_): _description_
"""
login_window.setObjectName("login_window")
login_window.resize(291, 800)
login_window.setTabShape(QtWidgets.QTabWidget.TabShape.Rounded)
login_window.setWindowIcon(QtGui.QIcon(user_icon))
self.centralwidget = QtWidgets.QWidget(login_window)
self.centralwidget.setObjectName("centralwidget")
self.login_button = QtWidgets.QPushButton(self.centralwidget)
self.login_button.setGeometry(QtCore.QRect(10, 10, 271, 31))
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.login_button.setFont(font)
self.login_button.setObjectName("login_button")
self.save_button = QtWidgets.QPushButton(self.centralwidget)
self.save_button.setGeometry(QtCore.QRect(10, 110, 271, 31))
self.save_button.setObjectName("save_button")
self.user_input = QtWidgets.QLineEdit(self.centralwidget)
self.user_input.setGeometry(QtCore.QRect(10, 50, 271, 25))
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.user_input.setFont(font)
self.user_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.user_input.setObjectName("user_input")
self.password_input = QtWidgets.QLineEdit(self.centralwidget)
self.password_input.setGeometry(QtCore.QRect(10, 80, 271, 25))
font = QtGui.QFont()
font.setFamily("Nunito Sans")
self.password_input.setFont(font)
self.password_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.password_input.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_input.setObjectName("password_input")
login_window.setCentralWidget(self.centralwidget)
self.add_buttons(login_window) # 添加按钮和滚动条
self.retranslate_ui(login_window)
QtCore.QMetaObject.connectSlotsByName(login_window)
def add_buttons(self, login_window):
scroll_area = QtWidgets.QScrollArea(login_window)
scroll_area.setWidgetResizable(True)
scroll_area.setGeometry(QtCore.QRect(10, 500, 271, 25))
content_widget = QtWidgets.QWidget()
scroll_area.setWidget(content_widget)
layout = QtWidgets.QVBoxLayout(content_widget)
for i in range(10):
button = QtWidgets.QPushButton(f"Button {i+1}")
layout.addWidget(button)
self.centralwidget.setLayout(QtWidgets.QVBoxLayout())
self.centralwidget.layout().addWidget(scroll_area)
def retranslate_ui(self, login_window):
translate = QtCore.QCoreApplication.translate
login_window.setWindowTitle(translate("login_window", "AGV"))
self.login_button.setText(translate("login_window", "登录AGV"))
self.save_button.setText(translate("login_window", "保存密码"))
self.user_input.setPlaceholderText(translate("login_window", "请输入账号"))
self.password_input.setPlaceholderText(translate("login_window", "请输入密码"))

pyqt_login-master/assets/style.css

QLabel
{
color: grey;
}
#centralwidget, QMessageBox
{
background-color: #d3efff;
}
QScrollArea{
background-color: #d3efff;
}
QScrollArea QPushButton{
background-color: #409efe;
margin:0px 10px;
}
QPushButton
{
color: gray;
border: 1px solid #409efe;
border-radius: 10;
}
QPushButton:hover:!pressed
{
border-color: green;
}
QLineEdit
{
border: 1px solid #409efe;
border-radius: 10;
}
posted on   超级无敌美少男战士  阅读(196)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示