Palette – Stores a mapping from bitmap pixel palette_indexes to display colors

Map a pixel palette_index to a full color. Colors are transformed to the display’s format internally to save memory.

class displayio.Palette(color_count)

Create a Palette object to store a set number of colors.

Parameters:color_count (int) – The number of colors in the Palette

Returns the number of colors in a Palette

__setitem__(index, value)

Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1.

The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), bytearray, or a tuple or list of 3 integers.

This allows you to:

palette[0] = 0xFFFFFF                     # set using an integer
palette[1] = b'\xff\xff\x00'              # set using 3 bytes
palette[2] = b'\xff\xff\x00\x00'          # set using 4 bytes
palette[3] = bytearray(b'\x00\x00\xFF')   # set using a bytearay of 3 or 4 bytes
palette[4] = (10, 20, 30)                 # set using a tuple of 3 integers