PyQt5 - Login Form

In this PyQt5 blog of Python, I will show you a simple and attractive login form.

In this PyQt5 blog of Python, I will show you a simple and attractive login form.
 
Requirement
 
Python IDLE 3.7
 
Before moving on here, you should read my previous articles that will be very useful to you:
Source code
  1. from PyQt5 import QtCore, QtGui, QtWidgets  
  2.   
  3. class Ui_Dialog(object):  
  4.     def setupUi(self, Dialog):  
  5.         Dialog.setObjectName("Dialog")  
  6.         Dialog.resize(812632)  
  7.         Dialog.setStyleSheet("background-color: rgb(0, 170, 255);")  
  8.         self.frame = QtWidgets.QFrame(Dialog)  
  9.         self.frame.setGeometry(QtCore.QRect(9080631461))  
  10.         self.frame.setStyleSheet("background-color: rgb(255, 255, 255);")  
  11.         self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)  
  12.         self.frame.setFrameShadow(QtWidgets.QFrame.Raised)  
  13.         self.frame.setObjectName("frame")  
  14.         self.label = QtWidgets.QLabel(self.frame)  
  15.         self.label.setGeometry(QtCore.QRect(2308017151))  
  16.         font = QtGui.QFont()  
  17.         font.setPointSize(16)  
  18.         self.label.setFont(font)  
  19.         self.label.setStyleSheet("color: rgb(255, 0, 0);")  
  20.         self.label.setObjectName("label")  
  21.         self.label_2 = QtWidgets.QLabel(self.frame)  
  22.         self.label_2.setGeometry(QtCore.QRect(9019012131))  
  23.         font = QtGui.QFont()  
  24.         font.setPointSize(12)  
  25.         self.label_2.setFont(font)  
  26.         self.label_2.setObjectName("label_2")  
  27.         self.label_3 = QtWidgets.QLabel(self.frame)  
  28.         self.label_3.setGeometry(QtCore.QRect(9026012121))  
  29.         font = QtGui.QFont()  
  30.         font.setPointSize(12)  
  31.         self.label_3.setFont(font)  
  32.         self.label_3.setObjectName("label_3")  
  33.         self.lineEdit = QtWidgets.QLineEdit(self.frame)  
  34.         self.lineEdit.setGeometry(QtCore.QRect(26019023131))  
  35.         self.lineEdit.setStyleSheet("background-color: rgb(209, 207, 255);")  
  36.         self.lineEdit.setObjectName("lineEdit")  
  37.         self.lineEdit_2 = QtWidgets.QLineEdit(self.frame)  
  38.         self.lineEdit_2.setGeometry(QtCore.QRect(26026023131))  
  39.         self.lineEdit_2.setStyleSheet("background-color:#d1cfff;")  
  40.         self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)  
  41.         self.lineEdit_2.setObjectName("lineEdit_2")  
  42.         self.pushButton = QtWidgets.QPushButton(self.frame)  
  43.         self.pushButton.setGeometry(QtCore.QRect(35036016141))  
  44.         font = QtGui.QFont()  
  45.         font.setPointSize(14)  
  46.         self.pushButton.setFont(font)  
  47.         self.pushButton.setStyleSheet("background-color: rgb(0, 170, 0);")  
  48.         self.pushButton.setObjectName("pushButton")  
  49.         self.pushButton_2 = QtWidgets.QPushButton(self.frame)  
  50.         self.pushButton_2.setGeometry(QtCore.QRect(22036010141))  
  51.         self.pushButton_2.setStyleSheet("background-color:#ffff7f;")  
  52.         self.pushButton_2.setObjectName("pushButton_2")  
  53.   
  54.         self.retranslateUi(Dialog)  
  55.         QtCore.QMetaObject.connectSlotsByName(Dialog)  
  56.   
  57.     def retranslateUi(self, Dialog):  
  58.         _translate = QtCore.QCoreApplication.translate  
  59.         Dialog.setWindowTitle(_translate("Dialog""Dialog"))  
  60.         self.label.setText(_translate("Dialog""Log in Form"))  
  61.         self.label_2.setText(_translate("Dialog""User Name"))  
  62.         self.label_3.setText(_translate("Dialog""Password"))  
  63.         self.pushButton.setText(_translate("Dialog""Log in"))  
  64.         self.pushButton_2.setText(_translate("Dialog""Sign up"))  
  65.   
  66.   
  67. if __name__ == "__main__":  
  68.     import sys  
  69.     app = QtWidgets.QApplication(sys.argv)  
  70.     Dialog = QtWidgets.QDialog()  
  71.     ui = Ui_Dialog()  
  72.     ui.setupUi(Dialog)  
  73.     Dialog.show()  
  74.     sys.exit(app.exec_())  
Source Description
  • Here, I imported PyQt5 and their extension modules such as QtWidgets, QtGui and QtCore.
  • Next, I created one Class and two functions to declare Python widgets.
  • Then I created a label for Form title by using QLabel and setGeomentory methods.
  • Next, I declared two line edits for getting input and two pushbuttons for posting data to Database along with their configuration like setobject name, setstylesheet, and setFont.
Output
 
Let’s run the above source using Python IDLE. The code runs available various Python IDE such as PyCharm, Spyder, and eclipse, etc.
  • Open the Python IDLE 3.7 and click on Run >> Run module.