Pyqt5 登录注册窗口

在这里插入图片描述

# _*_ coding:utf-8 _*_ 

# Python3.6.8 + Pyqt5

# ——创建时间:2020.7.16——

# 登录页面



import sys

import os

from PyQt5 import QtWidgets

from PyQt5.QtWidgets import *

from PyQt5.QtGui import *

# from PyQt5.QtCore import *

from PyQt5.QtCore import QObject, pyqtSlot, QUrl, Qt, QTimer, QThread, pyqtSignal



Base_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.append(Base_DIR)





# 登录页面

class DialogUI(QWidget):

    def __init__(self,parent=None):

        super(DialogUI,self).__init__(parent)

 

        self.setWindowTitle("登录")

        self.resize(450,350)

        #禁止最大化按钮

        # self.setWindowTitle.setWindowFlags(Qt.WindowMinimizeButtonHint)

        # 禁止窗口拉伸

        self.setFixedSize(self.width(), self.height())

        winRectangle =self.frameGeometry()

        centerPoint = QDesktopWidget().availableGeometry().center()

        winRectangle.moveCenter(centerPoint)

        self.move(winRectangle.topLeft())



        # 输入密码框

        Lindex = QFormLayout()

        # 管理员登录标签

        self.title = QLabel("管理员登录")

        self.title.setFixedHeight(100)

        self.title.setStyleSheet("font-size: 32px;")

        self.title.setAlignment(Qt.AlignCenter)

        # 用户名输入框

        self.userinput = QLineEdit()

        self.userinput.setFixedHeight(40)

        self.userinput.setMaximumWidth(380)

        self.userinput.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)

        self.userinput.setClearButtonEnabled(True)

        self.userinput.setPlaceholderText("请输入用户名")

        self.userinput.setStyleSheet("font-size: 18px;margin-left:50%;background: #f3f3f3;border-radius:4px;border: 1px solid #999999;background-image: url(./image/user.png);background-repeat: no-repeat;background-position: left;color: #252424;padding: 0 0 0 35;")



        self.label1 = QLabel()

        # 密码框

        self.passwdinput = QLineEdit()

        self.passwdinput.setFixedHeight(40)

        self.passwdinput.setMaximumWidth(380)

        self.passwdinput.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)

        self.passwdinput.setClearButtonEnabled(True)

        self.passwdinput.setPlaceholderText("请输入密码")

        self.passwdinput.setStyleSheet("font-size: 18px;margin-left:50%;background: #f3f3f3;border-radius:4px;border: 1px solid #999999;background-image: url(./image/pass.png);background-repeat: no-repeat;background-position: left;color: #252424;padding: 0 0 0 35;")

        self.passwdinput.setEchoMode(QLineEdit.Password)

        self.label2 = QLabel()

        # 记住密码,下次登录自动登录

        self.gouxuan = QCheckBox('保存密码,下次登录自动登录')

        self.gouxuan.move(winRectangle.topLeft())

        self.gouxuan.setMaximumWidth(380)

        self.gouxuan.setFixedHeight(40)

        self.gouxuan.setStyleSheet("font-size: 14px;margin-left:50%")

        self.gouxuan.setTristate(True)



        # 点击登录按钮

        self.label3 = QLabel()

        self.loginbutton = QPushButton("登 录")

        self.loginbutton.setFixedHeight(40)

        self.loginbutton.setMaximumWidth(380)

        self.loginbutton.setStyleSheet("font-size: 18px;margin-left:50%;color:#F0FFF0;background: #0020ff;border-radius:4px;border: 1px solid #0020ff")

        self.loginbutton.clicked.connect(lambda:self.textchanged())

        



        Lindex.addRow(self.title)

        Lindex.addRow(self.userinput)

        Lindex.addRow(self.label1)

        Lindex.addRow(self.passwdinput)

        # Lindex.addRow(label2)

        Lindex.addRow(self.gouxuan)

        # Lindex.addRow(label3)

        Lindex.addRow(self.loginbutton)

        self.setLayout(Lindex)



    # 获取登录信息

    def textchanged(self):

        username = self.userinput.text()

        password = self.passwdinput.text()

        gouxuan = self.gouxuan.isChecked()

        # self.func.login(username, password, gouxuan)





if __name__ == "__main__":

    app = QApplication(sys.argv)

    window = DialogUI()

    window.show()

    sys.exit(app.exec())

猜你喜欢

转载自blog.csdn.net/qq_40430818/article/details/110553693
今日推荐