Open In App
Related Articles

PyQt5 – QColorDialog

Improve Article
Save Article
Like Article

QColorDialog It is a dialog box of a color picker widget. A color picker is a graphical user interface widget, usually found within graphics software or online, used to select colors and sometimes to create color schemes. Below is how the QColorDialog looks like

It is popup type widget in PyQt5 it basic use is to allow user to choose the color this widget is very useful in designing application like paint.

Example :
In this we will create a PyQt5 application which when executed will open the color dialog and when user choose the color and close the dialog there will be our main window which has a label and its color will be same as of the color selected in the dialog.4

Below is the implementation

# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
class Window(QMainWindow):
    def __init__(self):
        # setting title
        self.setWindowTitle("Python ")
        # setting geometry
        self.setGeometry(100, 100, 500, 400)
        # calling method
        # showing all the widgets
    # method for components
    def UiComponents(self):
        # opening color dialog
        color = QColorDialog.getColor()
        # creating label to display the color
        label = QLabel(self)
        # setting geometry to the label
        label.setGeometry(100, 100, 200, 60)
        # making label multi line
        # setting stylesheet of the label
                            "border : 5px solid black;"
        # setting text to the label
        # setting graphic effect to the label
        graphic = QGraphicsColorizeEffect(self)
        # setting color to the graphic
        # setting graphic to the label
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output :

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 21 Jun, 2020
Like Article
Save Article
Similar Reads
Complete Tutorials