PyQt5 Tutorials
About Lesson

In this Python PyQt5 lesson we want to learn about Python PyQt5 MySQL Database Select Data, so we have already learned that how you can insert data in to 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 an HBoxLayout in QHBoxLayout add a label and lineedit
  • Add another HBoxLayout, you need to also add a label and lineedit in this layout
  • Add a VBoxLayout, in this layout add a QTableWidget with a QPushButton
  • In the QTableWidget select number of rows and columns, in our case it is 8 rows and 3 columns
  • At the end click on the main window and select layout vertically for all widgets



This is our design.

PyQt5 QTableWidget Selecting Data
PyQt5 QTableWidget Selecting Data



After completing the design you need to save the .ui file, iam going to name it select.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 selecting data from Mysql database in the QTableWidget, first we have connected our application with the wamp server using mysql connector, now we need to get the database with tablename from the lineedit, 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.




Run the complete code give the database and tablename, after that click on the button.

PyQt5 Selecting Data from Mysql in QTableWidget
PyQt5 Selecting Data from Mysql in QTableWidget