Tables can be created with the QTableWidget. It is an item-based table view, similar to what you would see in Excel.

You can include the table widget as part of your gui, or popup a window with an excel like table.

In this example (PyQt5) it’ll show a window with the table, but you can make it part of your window gui with designer.

Download Examples:
Download PyQt examples



The QTableWidget is a table widget with rows and columns.

The object has the methods .setRowCount(x) and .setColumnCount(y), where x is number of rows and y number of columns. You could use this as self.setRowCount(5).

pyqt table

The contents is set with self.setItem(m, n, newitem), where m and n is the coordinate inside the table.

The variable newitem is of type QTableWidgetItem, which can take a text value as string. For instance: .setItem(1,2, QTableWidgetItem("Table Cell"))

Download Examples:
Download PyQt examples

Table in PyQT

The table is defined with the variable data.

data = {'col1':['1','2','3','4'],

The example below creates a table with 3 columns and a number of rows.

from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
import sys

data = {'col1':['1','2','3','4'],

class TableView(QTableWidget):
def __init__(self, data, *args):
QTableWidget.__init__(self, *args) = data

def setData(self):
horHeaders = []
for n, key in enumerate(sorted(
for m, item in enumerate([key]):
newitem = QTableWidgetItem(item)
self.setItem(m, n, newitem)

def main(args):
app = QApplication(args)
table = TableView(data, 4, 3)

if __name__=="__main__":