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.
0/4
PyQt5 Tutorials
About Lesson

In this PyQt5 Tutorial we are going to learn about Creating Mysql Database in PyQt5, in this lesson we want to learn how you can create mysql database with pyqt5 gui application. for this purpose we are going to use a library that is called mysql connector, so it is MySQL driver written in Python which does not depend on MySQL C client libraries and implements the DB API v2.0 specification (PEP-249).

 

 

You can simply use pip for the installation.

 

 

Also you need to download and install Wamp Server, because we want to use Wamp Server as virtual server for the mysql database.

 

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 two buttons
  • Also you need to add a label and at the end make the window layout vertically 
  • You need to add a vertical spacer between your lineedit and buttons

 

 

This is the design.

PyQt5 Mysql Design
PyQt5 Mysql Design

 

 

After completing the design you need to save the .ui file, iam going to name it database.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 two new methods in the file, the first method is for creating the database in our Wamp Server. we have just connected our application with the wamp server using mysql.connector library that we have already installed and we execute query for creating table.

 

 

the second method is for checking the database connection.

 

 

Also we have connected these methods with the clicked signal of QPushButton.

 

 

 

So now run the code, give the name of the database and click on the create database.

PyQt5 Tutorial - Creating Mysql Database in PyQt5
PyQt5 Tutorial – Creating Mysql Database in PyQt5

 

 

 

And if you check your wamp server, now we have a database of pyqt5 in their.

PyQt5 Wamp Server
PyQt5 Wamp Server
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