Palette

Simple colour palette widget in linear or grid layouts for PyQt5/PySide2
Heads up! You've already completed this tutorial.

This simple custom colour palette widget for PyQt5 and PySide2 accepts a list of colours when created, and presents these colours as an array of coloured buttons to click. Clicking on a button emits a signal with the clicked colour. Perfect to use in a bitmap drawing application or any Python GUI that needs a color picker.

Three palette widgets are provided —

PaletteHorizontal — Linear Horizontal Colour Palette

PaletteHorizontal displays colours in a linear horizontal palette.

Horizontal Palette widget in PyQt5 Horizontal Palette widget

PaletteGrid — Grid Colour Palette

PaletteGrid displays colours in a grid layout. This also accepts an optional second parameter n_columns, which is the number of columns to lay the colours out in. The default is 5 (as seen below).

python
PaletteGrid('17undertones', n_columns=5)

GridLayout Palette with 17 undertones in PyQt5 GridLayout Palette with 17 undertones

PaletteVertical — Vertical Colour Palette

There is also a vertical layout PaletteVertical available.

Built-in Colour Schemes

There are 3 built-in named colour-schemes paired12, category10 and 17undertones.

Paired 12 grid palette in PyQt5 Paired 12 grid palette

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Save time and build better with this book. Over 15K copies sold.

Get the book

Custom Colour Lists

You can also provide any list of colours you like when creating the widget.

python
PaletteGrid(['#000003', '#160B39', '#410967', '#6A176E', '#932567', '#BA3655', '#DC5039', '#F2751A', '#FBA40A', '#F6D542', '#FCFEA4'])

Bokeh Inferno 11 custom colour palette Bokeh Inferno 11

Signals

The palette provides only a single signal .selected which is emitted when a colour is selected in the palette. This sends the selected colour, in the same format as it was when setting the palette.

python
palette = PaletteHorizontal(['#000003', '#160B39', '#410967'])
palette.selected.connect(print)

The above would print to the console #000003 or #160B39 or #410967 as each colour was clicked.

1:1 Coaching & Tutoring for your Python GUIs project
Martin Fitzpatrick Python GUIs Coaching & Training
60 mins ($195) Book Now

1:1 Python GUIs Coaching & Training

Comprehensive code reviewBugfixes & improvements • Maintainability advice and architecture improvements • Design and usability assessment • Suggestions and tips to expand your knowledgePackaging and distribution help for Windows, Mac & Linux • Find out more.

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

Palette was written by Martin Fitzpatrick.

Martin Fitzpatrick is the creator of Python GUIs, and has been developing Python/Qt applications for the past 12+ years. He has written a number of popular Python books and provides Python software development & consulting for teams and startups.