Skip to content

SelectTag

mininterface.tag.SelectTag

Handle options – radio buttons / select box. The value serves as the initially selected choice. It is constrained to those defined in the options attribute.

options: OptionsType | None = None

The possible values.

m.form({"My restrained": SelectTag(options=("one", "two"))})

You can denote the options in many ways. Either put options in an iterable, or to a dict with keys as a values. You can also you tuples for keys to get a table-like formatting. Use the Enums or nested Tags... See the OptionsType for more details.

Here we focus at the SelectTag itself and its Options alias. It can be used to annotate a default value in a dataclass.

from dataclasses import dataclass
from typing import Annotated
from mininterface import run, Options
from mininterface.tag import SelectTag

@dataclass
class Env:
    foo: Annotated["str", Options("one", "two")] = "one"
    # `Options` is an alias for `SelectTag(options=)`
    #   so the same would be:
    # foo: Annotated["str", SelectTag(options=("one", "two"))] = "one"

m = run(Env)
m.form()  # prompts a dialog
Form choice

Tip

When dealing with a simple use case, use the mininterface.select dialog.

update(ui_value)

ui_value is one of the self.options values