Open In App
Related Articles

PyQt5 – QTableWidget

Improve Article
Save Article
Like Article

In this article, we will learn how to add and work with a table in our PyQt5 application. A table is an arrangement of data in rows and columns and widely used in communication, research, and data analysis. We can add one or more tables in our PyQt application using QTableWidget.

For a better understanding of the concept, we will take an example where we want to display the name and the city of different people in a table in our application. We can extract the data from a database, JSON file, or any other storage platform.


import sys
from PyQt5.QtWidgets import * 
#Main Window
class App(QWidget):
    def __init__(self):
        self.title = 'PyQt5 - QTableWidget'
        self.left = 0 = 0
        self.width = 300
        self.height = 200
        self.setGeometry(self.left,, self.width, self.height)
        self.layout = QVBoxLayout()
        #Show window
    #Create table
    def createTable(self):
        self.tableWidget = QTableWidget()
        #Row count
        #Column count
        self.tableWidget.setItem(0,0, QTableWidgetItem("Name"))
        self.tableWidget.setItem(0,1, QTableWidgetItem("City"))
        self.tableWidget.setItem(1,0, QTableWidgetItem("Aloysius"))
        self.tableWidget.setItem(1,1, QTableWidgetItem("Indore"))
        self.tableWidget.setItem(2,0, QTableWidgetItem("Alan"))
        self.tableWidget.setItem(2,1, QTableWidgetItem("Bhopal"))
        self.tableWidget.setItem(3,0, QTableWidgetItem("Arnavi"))
        self.tableWidget.setItem(3,1, QTableWidgetItem("Mandsaur"))
        #Table will fit the screen horizontally
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 11 May, 2020
Like Article
Save Article
Similar Reads
Complete Tutorials