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.
Related Course: Create GUI Apps with Python PyQt5
Tables
QTableWidget
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)
.
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"))
Related Course: Create GUI Apps with Python PyQt5
Table in PyQT
The table is defined with the variable data.
1 | data = {'col1':['1','2','3','4'], |
The example below creates a table with 3 columns and a number of rows.
1 |
|
If you are new to Python PyQt, then I highly recommend this book.