This is the 25th day of my participation in the August Challenge

This example shows how to open the main interface through the login interface.

Before we start implementing the login world, let’s give you a general overview of PyQt5 installation and use

PyQt5 is easy to use

The installation

PIP Install PyQt5 Pip3.5 Install PyQt5-Tools

Interface operation

1. Enter Designer in Win +R and press Enter to start Designer. Generally, select “Main Window” and click “Create” to Create it.

If there is no response after entering Designer in Win +R and pressing Enter, you can directly search Designer

 

2. After creation, you can use Qt Designer to easily and quickly draw the corresponding Box body, such as adding the drop-down control through the Combo Box; Add a Button via a Push Button; Add a List box via the List Widget; Use the Table Widget to add a data Table box, set the number of columns in the Table (right-click -edit Items-colums), adjust the box position and text size, background color, and windowTitle to optimize the interface display.

 

3. Click Save to generate the *. UI file (test. UI in this example) and save it in the D:\py\deploy folder

2. The login page is displayed


import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
Create the main window
class MainWindow(QMainWindow) :
    def __init__(self, *args, **kwargs) :
        super().__init__(*args, **kwargs)
        self.setWindowTitle('Home screen')
        self.showMaximized()
# dialog
class logindialog(QDialog) :
    def __init__(self, *args, **kwargs) :
        super().__init__(*args, **kwargs)
        self.setWindowTitle('Login screen')
        self.resize(200.200)
        self.setFixedSize(self.width(), self.height())
        self.setWindowFlags(Qt.WindowCloseButtonHint)

        ###### Set interface controls
        self.frame = QFrame(self)
        self.verticalLayout = QVBoxLayout(self.frame)

        self.lineEdit_account = QLineEdit()
        self.lineEdit_account.setPlaceholderText("Please enter your account number")
        self.verticalLayout.addWidget(self.lineEdit_account)

        self.lineEdit_password = QLineEdit()
        self.lineEdit_password.setPlaceholderText("Please enter your password")
        self.verticalLayout.addWidget(self.lineEdit_password)

        self.pushButton_enter = QPushButton()
        self.pushButton_enter.setText("Sure")
        self.verticalLayout.addWidget(self.pushButton_enter)

        self.pushButton_quit = QPushButton()
        self.pushButton_quit.setText("Cancel")
        self.verticalLayout.addWidget(self.pushButton_quit)

        ###### Bind button event
        self.pushButton_enter.clicked.connect(self.on_pushButton_enter_clicked)
        self.pushButton_quit.clicked.connect(QCoreApplication.instance().quit)

    def on_pushButton_enter_clicked(self) :
        # Account judgment
        if self.lineEdit_account.text() == "":
            return

        # password judgment
        if self.lineEdit_password.text() == "":
            return

        Close the dialog box and return 1
        self.accept()

# Getting started
if __name__ == "__main__":
    app = QApplication(sys.argv)
    dialog = logindialog()
    if  dialog.exec_()==QDialog.Accepted:
        the_window = MainWindow()
        the_window.show()
        sys.exit(app.exec_())
Copy the code