from PyQt5.QtGui import QColor # creating a QColor with red color red_color = QColor(255, 0, 0) # creating a QColor with green color green_color = QColor(0, 255, 0) # creating a QColor with blue color blue_color = QColor(0, 0, 255)
from PyQt5.QtGui import QColor from PyQt5.QtWidgets import QWidget, QApplication app = QApplication([]) window = QWidget() # setting the background color of the widget using a QColor object window.setAutoFillBackground(True) palette = window.palette() palette.setColor(window.backgroundRole(), QColor(255, 255, 255)) # white color window.setPalette(palette) window.show() app.exec_()In the above example, we create a PyQt5 QWidget and set its background color using QColor object. The `setAutoFillBackground(True)` method must be called for the widget to use the palette. The package library used here is PyQt5.