Skip to content

number_stepper

pdwidgets.widgets.number_stepper

Numeric stepper widget.

NumberStepper(parent, x=0, y=0, w=None, h=None, align=None, align_to=None, fg=None, bg=None, visible=True, value=0, padding=None, step=1, minimum=None, maximum=None, number_format='{}')

Bases: Widget

Bounded numeric stepper with - / + buttons.

Initialize a NumberStepper: a - button, a value display and a + button for adjusting a bounded number.

This generalizes the ad-hoc +/- :class:IconButton pattern into a reusable widget. Pressing a button changes value by step, clamped to [minimum, maximum] when those are given, and fires the change callback.

Parameters:

Name Type Description Default
parent Widget

The parent widget or screen that contains this stepper.

required
x int

The x-coordinate of the stepper.

0
y int

The y-coordinate of the stepper.

0
w int

The width of the stepper.

None
h int

The height of the stepper.

None
align int

The alignment of the stepper.

None
align_to Widget

The widget to align to.

None
fg int

The value-text color; defaults to on_surface.

None
bg int

The background color; defaults to surface_variant.

None
visible bool

The visibility of the stepper.

True
value int | float

The initial value (default 0).

0
padding tuple

The padding on each side of the stepper.

None
step int | float

Amount added/subtracted per press (default 1).

1
minimum int | float

Lower clamp bound, or None for unbounded.

None
maximum int | float

Upper clamp bound, or None for unbounded.

None
number_format str

str.format spec for the value display.

'{}'
Usage

temp = NumberStepper(card, value=20, minimum=15, maximum=30) temp.set_change_cb(lambda s: print("set", s.value))

changed()

Clamp the value to the configured bounds and refresh the display.