Course Content
PyQt5 Basics – Installation Process, Qt Designer Intro
In this part we are going to talk about some basics functionalities in PyQt5, we go through installation process, creating QPushButton, Signals and working with Qt Designer.
PyQt5 Tutorials
About Lesson

In this PyQt5 Tutorial we want to learn about Inserting Data to Mysql Database in PyQt5, and we are using mysql connector for this purpose, in the previous lesson we have learned how you can create database using pyqt5 gui application, now you need to create a table in the database and my table name is users.



Now 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 HBoxLayout and in the HBoxLayout add a label and a lineedit
  • Add another HBoxLayout, and in the HBoxLayout add label and lineedit
  • Also you need to add a label and button at the end and make the window layout vertically 
  • You need to add a vertical spacer between your lineedit and buttons




This is our design.

PyQt5 Mysql Design
PyQt5 Mysql Design




After completing the design you need to save the .ui file, iam going to name it insert.ui, now copy the file and paste it in the Scripts folder of your Python installation, because we want to convert our ui file in to python file and for converting you need to use pyuic5 module. pyuic5 module is located in the Scripts folder of your Python installation, run this command for converting in your terminal.

So this is the converted file, also we have brought some changes to this file.




We have added one method for inserting data to the database, first we have connected our application with the wamp server using mysql connector, after that we need to create the object of cursor, also we need to get the value from the QLineEdit, at the end we need to execute the query.




Also we have connected our QPushButton clicked signal with this method.




So now run the code and give the email and password and click on insert data button.

PyQt5 Tutorial - Inserting Data to Mysql Database in PyQt5
PyQt5 Tutorial – Inserting Data to Mysql Database in PyQt5




If you see your wamp server, you have the inserted data.

 Inserting Data to Mysql Database in PyQt5
Inserting Data to Mysql Database in PyQt5
Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found