ColorPicker#

New in version 1.0.0.

Create, share, and apply color palettes to your UI, as well as measure the accessibility level of any color combination..

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/color-picker-preview.png

Usage#

from typing import Union

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.pickers import MDColorPicker

KV = '''
MDScreen:

    MDTopAppBar:
        id: toolbar
        title: "MDTopAppBar"
        pos_hint: {"top": 1}

    MDRaisedButton:
        text: "OPEN PICKER"
        pos_hint: {"center_x": .5, "center_y": .5}
        md_bg_color: toolbar.md_bg_color
        on_release: app.open_color_picker()
'''


class MyApp(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def open_color_picker(self):
        color_picker = MDColorPicker(size_hint=(0.45, 0.85))
        color_picker.open()
        color_picker.bind(
            on_select_color=self.on_select_color,
            on_release=self.get_selected_color,
        )

    def update_color(self, color: list) -> None:
        self.root.ids.toolbar.md_bg_color = color

    def get_selected_color(
        self,
        instance_color_picker: MDColorPicker,
        type_color: str,
        selected_color: Union[list, str],
    ):
        '''Return selected color.'''

        print(f"Selected color is {selected_color}")
        self.update_color(selected_color[:-1] + [1])

    def on_select_color(self, instance_gradient_tab, color: list) -> None:
        '''Called when a gradient image is clicked.'''


MyApp().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/color-picker-usage.png

API - kivymd.uix.pickers.colorpicker.colorpicker#

class kivymd.uix.pickers.colorpicker.colorpicker.MDColorPicker(**kwargs)#

ModalView class. See module documentation for more information.

Events:
on_pre_open:

Fired before the ModalView is opened. When this event is fired ModalView is not yet added to window.

on_open:

Fired when the ModalView is opened.

on_pre_dismiss:

Fired before the ModalView is closed.

on_dismiss:

Fired when the ModalView is closed. If the callback returns True, the dismiss will be canceled.

Changed in version 1.11.0: Added events on_pre_open and on_pre_dismiss.

Changed in version 2.0.0: Added property ‘overlay_color’.

Changed in version 2.1.0: Marked attach_to property as deprecated.

adjacent_color_constants#

A list of values that are used to create the gradient. These values are selected empirically. Each of these values will be added to the selected RGB value, thus creating colors that are close in value.

adjacent_color_constants is an ListProperty and defaults to [0.299, 0.887, 0.411].

default_color#

Default color value The set color value will be used when you open the dialog.

default_color is an ColorProperty and defaults to None.

type_color#

Type of color. Available options are: ‘RGBA’, ‘HEX’, ‘RGB’.

type_color is an OptionProperty and defaults to ‘RGB’.

background_down_button_selected_type_color#

Button background for choosing a color type (‘RGBA’, ‘HEX’, ‘HSL’, ‘RGB’).

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/color-picker-background-down-button-selected-type-color.png

background_down_button_selected_type_color is an ColorProperty and defaults to [1, 1, 1, 0.3].

radius_color_scale#

The radius value for the color scale.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/color-picker-gradient-scale-radius.png

radius is an VariableListProperty and defaults to [8, 8, 8, 8].

text_button_ok#

Color selection button text.

text_button_ok is an StringProperty and defaults to ‘SELECT’.

text_button_cancel#

Cancel button text.

text_button_cancel is an StringProperty and defaults to ‘CANCEL’.

selected_color#
update_color_slider_item_bottom_navigation(self, color: list)#

Updates the color of the slider that sets the transparency value of the selected color and the color of bottom navigation items.

update_color_type_buttons(self, color: list)#

Updating button colors (display buttons of type of color) to match the selected color.

get_rgb(self, color: list)#

Returns an RGB list of values from 0 to 255.

on_background_down_button_selected_type_color(self, instance_color_picker, color: list)#
on_type_color(self, instance_color_picker, type_color: str = '', interval: Union[float, int] = 0)#

Called when buttons are clicked to set the color type.

on_open(self)#

Default open event handler.

on_select_color(self, color: list)#

Called when a gradient image is clicked.

on_switch_tabs(self, bottom_navigation_instance, bottom_navigation_item_instance, name_tab)#

Called when switching tabs of bottom navigation.

on_release(self, *args)#

Called when the SELECT button is pressed