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#

Convenience function#

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

result = bs.ask_color(title="Background Color", color="#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", color="#ff0000")
dlg.show()

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

Chooser layout#

The dialog shows a hue/saturation spectrum with a luminance slider below it. Numeric fields on the right allow direct entry in RGB, HSL, or hex notation. A dropper button (Windows/Linux only) lets the user sample any pixel on the desktop.

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 using a hue/saturation spectrum.

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", color="#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", color="#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.HStack(gap=8):
18        bs.Button("ask_color()",          on_click=show_chooser)
19        bs.Button("ColorChooserDialog()", on_click=show_custom)
20
21app.run()