tkmilan.menu#

Create Menu elements.

See the underlying models in model.MenuElement and similar.

Module Attributes

childT

Type-Checking variable type for process function.

childrenT

Type-Checking variable for processed elements.

Functions

Checkbox(label[, default, variable, id])

Wrap model.MenuElementCheckbox with a nicer interactive API.

Label(label, *[, id])

Wrap model.MenuElementLabel with a nicer interactive API.

Radio(spec, *[, prefixid])

Create several model.MenuElementRadio with a nicer interactive API.

Separator(*[, id])

Wrap model.MenuElementSeparator with a nicer interactive API.

Sub(label, rawchildren, *[, id, wstate_single])

Wrap model.MenuElementCascade with a nice interactive API.

process(*children)

Process menu definition objects into "proper" MenuElement objects.

Classes

Root(*children)

Define the menu root element, a simple tuple of children.

class tkmilan.menu.Root(*children: MenuElement | None | str | SpecParsed | VSpec | Tuple[str, Boolean | None | bool | SpecParsed | VSpec])#

Bases: tuple

Define the menu root element, a simple tuple of children.

Wraps the process function.

tkmilan.menu.Checkbox(label: str, default: bool | None = None, *, variable: Boolean | None = None, id: str | None = None) MenuElementCheckbox#

Wrap model.MenuElementCheckbox with a nicer interactive API.

This concerns automatic id calculation. Use an incrementing counter.

It also supports creating a new variable with a default value.

tkmilan.menu.Label(label: str, *, id: str | None = None) MenuElementLabel#

Wrap model.MenuElementLabel with a nicer interactive API.

This concerns automatic id calculation. Use an incrementing counter.

tkmilan.menu.Radio(spec: VSpec, *, prefixid: str | None = None) Sequence[MenuElementRadio]#

Create several model.MenuElementRadio with a nicer interactive API.

Takes a specification object and returns a series of model.MenuElementRadio.

This concerns automatic id calculation. Use an incrementing counter, with an optional prefixid, also created with an incrementing counter. This always creates a new variable, based on the spec.

When squashing all elements at the same level, use like this:

...
'P Label',
*Radio(spec),
'N Label',
...

When putting them on a nested sub-menu, use like this:

...
menu.Sub('Nested Radio', Radio(spec),
         wstate_single=True)
...
tkmilan.menu.Separator(*, id: str | None = None) MenuElementSeparator#

Wrap model.MenuElementSeparator with a nicer interactive API.

This concerns automatic id calculation. Use an incrementing counter.

tkmilan.menu.Sub(label: str, rawchildren: Sequence[MenuElement | None | str | SpecParsed | VSpec | Tuple[str, Boolean | None | bool | SpecParsed | VSpec]], *, id: str | None = None, wstate_single: bool | None = None) MenuElementCascade#

Wrap model.MenuElementCascade with a nice interactive API.

This concerns automatic id calculation. Derive from the label.

tkmilan.menu.process(*children: MenuElement | None | str | SpecParsed | VSpec | Tuple[str, Boolean | None | bool | SpecParsed | VSpec]) Tuple[MenuElement, ...]#

Process menu definition objects into “proper” MenuElement objects.

All given model.MenuElement are used directly. The other object types are:

All other types are unsupported and produce an error.

Note

You should not need to use this function directly. See Root, Sub, or define the children directly in setup_menu function.

tkmilan.menu.childT#

Type-Checking variable type for process function.

alias of Union[MenuElement, None, str, SpecParsed, VSpec, Tuple[str, Union[Boolean, None, bool, SpecParsed, VSpec]]]

tkmilan.menu.childrenT#

Type-Checking variable for processed elements.

alias of Tuple[MenuElement, …]