PyQt5 Tutorial – Simple Login with MySQL in PyQt5

In this PyQt5 Tutorial we want to learn creating of Simple Login with MySQL in PyQt5, before this we have learned how you can work with mysql database and pyqt5, we have learned about mysql database connection, inserting data and selecting data from mysql database in pyqt5. you can check the articles in the below links.

 

 

 

 

As i have already said we want to use MySQL Connector, you need to install this library.

 

 

 

Make sure that you have already installed Wamp Server, and you have the database and table in your Wamp Server, you need to read the previous articles that i have already added the links at the top.

 

Open your Qt Designer,  you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create Widget window. now we add widgets in Qt Designer.

 

  • Add  QHBoxLayout in QHBoxLayout add a QLabel and QLinEdit
  • Add another QHBoxLayout, you need to also add a QLabel and QLineEdit in this layout
  • Add a QVBoxLayout, in this layout add a QLabel with a QPushButton
  • At the end click on the main window and select layout vertically for all widgets
  • Also you need to add a vertical spacer between the lineedits and button.

 

 

 

This is the design that we want.

PyQt5 Login Design
PyQt5 Login Design

 

 

 

After completing the design you need to save your design, the extension will be .ui file. now it is time to convert our .ui file in to .py file. there are two ways that you can do, first way is loading the ui file, the second way is converting the .ui file to .py file, we want to use the second way. for converting of the ui file to python file we need to use pyuic5 module, this module is located in the Scripts folder of your python installation, you need to copy your ui file in the Scripts folder of your Python installation. after that open the terminal in the Scripts folder, and run this command.

 

 

 

 

And this is the converted file, also we have added a method for login.

 

 

 

 

We have added one method in our file and that is for login, first we want to get the email and password from the user and after we compare that with the registered email an password of our database. in the successful login we want to open the second dialog.

 

 

 

 

Run the complete code give correct username and password.

PyQt5 Tutorial - Simple Login with MySQL in PyQt5
PyQt5 Tutorial – Simple Login with MySQL in PyQt5

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×