用python的pyqt5写登陆界面

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton


class Login(QWidget):
    def __init__(self):
        super().__init__()
        
        # 设置窗口标题
        self.setWindowTitle('登录')
        
        # 设置窗口尺寸
        self.setGeometry(400, 200, 300, 200)
        
        # 设置标签
        self.label_username = QLabel(self)
        self.label_username.setText('用户名:')
        self.label_username.move(50, 50)

        self.label_password = QLabel(self)
        self.label_password.setText('密码:')
        self.label_password.move(50, 90)

        # 设置文本框
        self.text_username = QLineEdit(self)
        self.text_username.move(100, 50)

        self.text_password = QLineEdit(self)
        self.text_password.setEchoMode(QLineEdit.Password)
        self.text_password.move(100, 90)

        # 设置登录按钮
        self.button_login = QPushButton('登录', self)
        self.button_login.move(100, 130)
        self.button_login.clicked.connect(self.handle_login)

    def handle_login(self):
        username = self.text_username.text()
        password = self.text_password.text()

        if username == 'admin' and password == '123456':
            print('登录成功!')
        else:
            print('用户名或密码错误!')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    login = Login()
    login.show()
    sys.exit(app.exec_())

猜你喜欢

转载自blog.csdn.net/yydsdeni/article/details/132590695