Skip to content

pyaccesskit.forms.controls

pyaccesskit.forms.controls

Specifications of form controls.

Each control kind is its own spec class; together they form the discriminated union :data:ControlSpec (kind is the discriminator). Positions and sizes are :class:~pyaccesskit.units.Length values and are optional: the layout engine places controls that have no explicit at=.

ControlSpec module-attribute

ControlSpec = Annotated[
    LabelSpec
    | TextBoxSpec
    | CheckBoxSpec
    | ComboBoxSpec
    | ButtonSpec,
    Field(discriminator="kind"),
]

Any control spec (a Pydantic discriminated union on kind).

ControlBase

Bases: SpecModel

Options shared by all controls.

Attributes:

Name Type Description
name str | None

Control name. Bound controls default to their field name.

section Section

Form section holding the control.

at tuple[Length, Length] | None

Explicit (left, top) position; None lets the layout engine place it.

width Length | None

Explicit width (defaults depend on the control kind).

height Length | None

Explicit height.

visible bool

Whether the control is visible in Form view.

properties dict[str, PropertyValue]

Other Access control properties to set verbatim (escape hatch).

control_kind property

control_kind: ControlKind

The kind of control.

bound_field property

bound_field: str | None

The bound field name, if the control is bound to a field.

attached_label property

attached_label: str | None

The attached label caption, or None if the control has no attached label.

LabelSpec

Bases: ControlBase

A free-standing label.

TextBoxSpec

Bases: _BoundControl

A text box bound to field or showing a calculated control_source ("=[Qty]*[Price]").

CheckBoxSpec

Bases: _BoundControl

A check box (typically bound to a Yes/No field).

ComboBoxSpec

Bases: _BoundControl

A combo box whose rows come from a table/query/SQL statement or a value list.

ButtonSpec

Bases: ControlBase

A command button, optionally running VBA when clicked.