Color Dialog#
bs.ask_color() opens a modal color chooser and returns the selected color.
ColorChooserDialog gives the same chooser as a reusable object.
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 |
|---|---|
|
|
|
|
|
Lowercase hex string, e.g. |
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 Dialogs — ask_string(), ask_integer(), and other value-input dialogs.
Font Dialog — ask_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:
Show a color chooser dialog. |
|
A dialog for choosing a color using a hue/saturation spectrum. |
|
A color selected from |
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()