import sys
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QLineEdit, QVBoxLayout, QHBoxLayout, QFrame
from PySide6.QtGui import QFont
class Login(QWidget):
def __init__(self):
super().__init__()
self.start_ui()
def start_ui(self):
self.generar_formulario()
self.show()
def generar_formulario(self):
self.main_layout = QVBoxLayout()
container_user = QFrame(self)
hbox_layout_user = QHBoxLayout(container_user)
user_label = QLabel('USUARIO: ', container_user)
self.user_input = QLineEdit(container_user)
font = QFont('Arial', 26)
font.setBold(True)
user_label.setFont(font)
hbox_layout_user.addWidget(user_label)
hbox_layout_user.addWidget(self.user_input)
container_password = QFrame(self)
hbox_layout_password = QHBoxLayout(container_password)
password_label = QLabel('CONTRASEÑA: ', container_password)
self.password_input = QLineEdit(container_password)
self.password_input.setEchoMode(QLineEdit.Password)
password_label.setFont(font)
hbox_layout_password.addWidget(password_label)
hbox_layout_password.addWidget(self.password_input)
self.main_layout.addWidget(container_user)
self.main_layout.addWidget(container_password)
self.button_validation = QPushButton('Validar', self)
self.button_validation.clicked.connect(self.Validar_Credenciales)
self.main_layout.addWidget(self.button_validation)
self.resul_label = QLabel(self)
#self.resul_label.setFont(QFont('Arial', 12))
self.main_layout.addWidget(self.resul_label)
container_user.move(50, 50)
container_password.move(50, 150)
self.button_validation.move(150, 250)
self.resul_label.move(60, 350)
#self.setLayout(self.main_layout)
def Validar_Credenciales(self):
usuario = "Pepe"
password = "123"
usuario_get = self.user_input.text()
contraseña_get = self.password_input.text()
if usuario_get == usuario and contraseña_get == password:
self.resul_label.setText(f"\tBienvenido {usuario},\n aqui tenemos recomendaciones de videos")
self.resul_label.adjustSize()
else:
self.resul_label.setText("Ingresa bien tu contraseña estupido")
self.resul_label.adjustSize()
if __name__ == '__main__':
app = QApplication(sys.argv)
login = Login()
sys.exit(app.exec())
我以为当我输入的一切都是正确的时,它会显示一个按钮
在标签下面写着欢迎使用用户