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..
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()
API - kivymd.uix.pickers.colorpicker.colorpicker
#
- class kivymd.uix.pickers.colorpicker.colorpicker.MDColorPicker(**kwargs)#
Base class for dialog movement behavior.
For more information, see in the
MotionBase
class documentation.- 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 anListProperty
and defaults to [0.299, 0.887, 0.411].
- default_color#
Default color value in (r, g, b, a) or string format. The set color value will be used when you open the dialog.
default_color
is anColorProperty
and defaults to None.
- type_color#
Type of color. Available options are: ‘RGBA’, ‘HEX’, ‘RGB’.
type_color
is anOptionProperty
and defaults to ‘RGB’.
- background_down_button_selected_type_color#
Button background for choosing a color type (‘RGBA’, ‘HEX’, ‘HSL’, ‘RGB’) in (r, g, b, a) or string format.
background_down_button_selected_type_color
is anColorProperty
and defaults to [1, 1, 1, 0.3].
- radius_color_scale#
The radius value for the color scale.
radius
is anVariableListProperty
and defaults to [8, 8, 8, 8].
- text_button_ok#
Color selection button text.
text_button_ok
is anStringProperty
and defaults to ‘SELECT’.
- text_button_cancel#
Cancel button text.
text_button_cancel
is anStringProperty
and defaults to ‘CANCEL’.
- selected_color#
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.
- on_type_color(self, instance_color_picker, type_color: str = '', interval: float | int = 0)#
Called when buttons are clicked to set the color type.
- on_open(self)#
Default open event handler.
- 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