PyQt5 Inserting Data In To Mysql Database

In this PyQt5 article we are going to talk about Inserting Data Into Mysql Database with

PyQt5,  so first of all you can read PyQt5 Mysql Database Connection article .  OK now we are

going to start our topic and also remember that we are using Wamp server as our virtual server.

 

 

 

Also you can check more Python GUI articles in the below links

1: Kivy GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Psyide2 GUI Development 

4: wxPython GUI Development Tutorials

5: PyQt5 GUI Development Tutorials

 

 

 

First we need some imports from PyQt5 also because of Database functionality we are

using MYSQLdb, you can read my article about MYSQLdb in the PyQt5 Database Connection.

 

 

 

 

 

After that we are going to create our Window class that extends from QDialog and we add

our Window requirements in the constructor of the class. we create two methods in the class, the

first method is for  setting our Window requirements in PyQt5,  also we create a QVBoxLayout with

two QLineEdit and one QPushButton.  the second method is the method that we do our Database

functionality i mean inserting data from the QLineEdit to Mysql database,  first we do connection

by using mdb.connect() and in the connect() we add our localhost, username, password and

database name,  remember that mdb is an alias to MYSQLdb, after that we execute our query

and give a QMessageBox to the user for successfully inserting data.

 

 

 

 

 

Also every PyQt5 application must create an application object. 

 

 

 

 

This is the mainloop of the application. The event handling starts from this point. 

 

 

 

 

 

Complete source code for PyQt5 Inserting Data In To Mysql Database

 

 

 

 

 

Run the complete code and this will be the result

PyQt5 Inserting Data In To Mysql Database
PyQt5 Inserting Data In To Mysql Database

 

 

 

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

7 thoughts on “PyQt5 Inserting Data In To Mysql Database”

  1. File “C:\Users\naomi\Desktop\Projet_Noe\inserttest.py”, line 65, in InsertData
    with con:

    AttributeError: __enter__

    There is a problem, but why ?

  2. Traceback (most recent call last):
    File “/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py”, line 5, in
    import MySQLdb as mdb
    ModuleNotFoundError: No module named ‘MySQLdb’

Comments are closed.

Codeloop
Share via
Copy link
Powered by Social Snap
×