Color Dialog#

bs.ask_color() opens a modal color chooser and returns the selected color. ColorChooserDialog gives the same chooser as a reusable object.

Color Dialog — light theme Color Dialog — dark theme

Usage#

Reach for the ask_color() verb by default — it covers the one-shot case. Drop to the ColorChooserDialog object only when you need to reuse the chooser or open it repeatedly.

Convenience function#

bs.ask_color() is the one-liner shorthand. Pass value= to pre-select an initial color (any CSS hex string):

result = bs.ask_color(title="Background Color", value="#1a1a2e")
if result:
    apply_background(result.hex)

The return value is a ColorChoice with three attributes:

Attribute

Description

rgb

(r, g, b) tuple, each 0–255.

hsl

(h, s, l) tuple: hue 0–360, saturation and luminance 0–100.

hex

Lowercase hex string, e.g. '#0070c0'.

None is returned if the user cancels.

Reusable dialog object#

Use ColorChooserDialog when you need to inspect the result after show() or show the same dialog multiple times:

from bootstack.dialogs import ColorChooserDialog

dlg = ColorChooserDialog(title="Pick a color", value="#ff0000")
dlg.show()

if dlg.result:
    r, g, b = dlg.result.rgb

Chooser layout#

The chooser has two tabs. Themed shows the active theme’s color families (primary, success, info, warning, danger, and a neutral gray) as light-to-dark bands — click any swatch to pick an on-theme color. Custom shows a hue/saturation field for picking any color freely. Both tabs share the luminance slider, live preview, and the numeric fields on the right, which allow direct entry in RGB, HSL, or hex notation.

Color Dialog custom tab — light theme Color Dialog custom tab — dark theme

See also#

Input Dialogsask_string(), ask_integer(), and other value-input dialogs.

Font Dialogask_font() for selecting a font.

API#

The complete reference for ask_color() and ColorChooserDialog (and its ColorChoice result) lives on the Dialogs API page. At a glance:

ask_color

Show a color chooser dialog.

ColorChooserDialog

A dialog for choosing a color.

ColorChoice

A color selected from ColorChooserDialog or ask_color.

Full Example#

 1
 2from bootstack.dialogs import ColorChooserDialog
 3def show_chooser():
 4    result = bs.ask_color(title="Choose Color", value="#0070C0")
 5    if result:
 6        print(f"Selected: hex={result.hex}  rgb={result.rgb}  hsl={result.hsl}")
 7
 8def show_custom():
 9    dlg = ColorChooserDialog(title="Background Color", value="#00B050")
10    dlg.show()
11    if dlg.result:
12        print(f"hex={dlg.result.hex}")
13
14with bs.App(title="Color Dialog", size=(680, 160), padding=20, gap=16) as app:
15
16    bs.Label("Color Dialog", font="heading-sm")
17    with bs.Row(gap=8):
18        bs.Button("ask_color()",          on_click=show_chooser)
19        bs.Button("ColorChooserDialog()", on_click=show_custom)
20
21app.run()