To help support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount on all books and courses.

New to Qt5 and Python? Check out the complete PyQt5 tutorial.

For [[ activeDiscount.description ]] I'm giving a [[ ]]% discount on my PyQt5 book and PySide2 book with the code [[ couponCode ]].


Simple colour palette in linear or grid layouts

This simple custom widget 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.

Three widgets are provided —

PaletteHorizontal a linear horizontal palette

Horizontal Palette widget Horizontal Palette widget

PaletteGrid a grid palette. 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).

PaletteGrid('17undertones', n_columns=5)

GridLayout Palette with 17 undertones GridLayout Palette with 17 undertones

There is also a vertical layout PaletteVertical available.

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

Paired 12 grid palette Paired 12 grid palette

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

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

Bokeh Inferno 11 Bokeh Inferno 11


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.

palette = PaletteHorizontal(['#000003', '#160B39', '#410967'])

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

Enjoyed this?
You might enjoy my books.

Create GUI Applications is my hands-on guide to making desktop apps with Python.

Stop searching for how to create GUI applications with Python — it's all here.

I've been teaching PyQt for 8 years, helping thousands of developers just like you to bring their apps to life. Let's make your project a success!

PySide6 Book PyQt5 Book PyQt6 Book PySide2 Book