from PyQt5.QtWidgets import QTableWidgetItem item = QTableWidgetItem("Text for the Item")
from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem table = QTableWidget() # Set the number of rows and columns table.setRowCount(2) table.setColumnCount(2) # Set the items for each cell item1 = QTableWidgetItem("A") table.setItem(0, 0, item1) item2 = QTableWidgetItem("B") table.setItem(0, 1, item2) item3 = QTableWidgetItem("C") table.setItem(1, 0, item3) item4 = QTableWidgetItem("D") table.setItem(1, 1, item4)This code creates a QTableWidget with two rows and two columns. It then creates four QTableWidgetItem instances and sets them to different cells in the table. The package library used in this code is PyQt5.QtWidgets.