from PyQt5.QtGui import QColor color = QColor("green")
import random from PyQt5 import QtWidgets, QtGui class Main(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.table = QtWidgets.QTableWidget(3,3) self.setCentralWidget(self.table) for row in range(self.table.rowCount()): for column in range(self.table.columnCount()): color = QtGui.QColor(random.choice(QtGui.QColor.colorNames())) brush = QtGui.QBrush(color) item = QtWidgets.QTableWidgetItem() item.setBackground(brush) self.table.setItem(row, column, item) app = QtWidgets.QApplication([]) window = Main() window.show() app.exec_()In this example, a random color name is selected using the choice() method from the QColor.colorNames() list. The QTableWidgetItem object is used to set the background brush color for each cell in the table widget.