Skip to content

dropdown

pdwidgets.widgets.dropdown

Dropdown selection widget.

Dropdown(parent, x=0, y=0, w=None, h=None, align=None, align_to=None, fg=None, bg=None, visible=True, value=None, padding=None, options=None, radius=6)

Bases: Widget

Header button that opens a modal list of options.

Initialize a Dropdown: a header button that reveals a popup option list.

Tapping the header opens a small popup (a shadowed :class:Card of option buttons) over the screen; tapping an option selects it, updates value and closes the popup; tapping anywhere else also closes it. The popup uses modal pointer capture (see :meth:Widget.set_modal) so the rest of the UI is inert while it is open.

Parameters:

Name Type Description Default
parent Widget

The parent widget or screen that contains this dropdown.

required
x int

The x-coordinate of the dropdown.

0
y int

The y-coordinate of the dropdown.

0
w int

The width of the dropdown header.

None
h int

The height of the dropdown header.

None
align int

The alignment of the dropdown.

None
align_to Widget

The widget to align to.

None
fg int

The text/arrow color; defaults to on_surface.

None
bg int

The header color; defaults to surface.

None
visible bool

The visibility of the dropdown.

True
value str

The initially selected option (defaults to the first).

None
padding tuple

The padding on each side of the dropdown.

None
options list

The list of option strings.

None
radius int

The corner radius of the header/popup (default 6).

6
Usage

dd = Dropdown(card, options=["Low", "Medium", "High"]) dd.set_change_cb(lambda s: print("chose", s.value))

changed()

Update the header label to the selected option.

draw(area=None)

Draw the dropdown header (rounded surface); repaint sub-areas flat.