# Select

> **Tip: Added in version 0.24.0**


A Select widget is a compact control to allow the user to select between a number of possible options.


- [X] Focusable
- [ ] Container


The options in a select control may be passed into the constructor or set later with `set_options`.
Options should be given as a sequence of tuples consisting of two values: the first is the string (or [Rich Renderable](https://rich.readthedocs.io/en/latest/protocol.html)) to display in the control and list of options, the second is the value of option.

The value of the currently selected option is stored in the `value` attribute of the widget, and the `value` attribute of the `Changed` message.


## Typing

The `Select` control is a typing Generic which allows you to set the type of the option values.
For instance, if the data type for your values is an integer, you would type the widget as follows:

```python
options = [("First", 1), ("Second", 2)]
my_select: Select[int] =  Select(options)
```

> **Note**
>
>
> Typing is entirely optional.
>
> If you aren't familiar with typing or don't want to worry about it right now, feel free to ignore it.


## Examples

### Basic Example

The following example presents a `Select` with a number of options.

**select_widget.py**


```python
from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Header, Select

LINES = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.""".splitlines()


class SelectApp(App):
    CSS_PATH = "select.tcss"

    def compose(self) -> ComposeResult:
        yield Header()
        yield Select((line, line) for line in LINES)

    @on(Select.Changed)
    def select_changed(self, event: Select.Changed) -> None:
        self.title = str(event.value)


if __name__ == "__main__":
    app = SelectApp()
    app.run()
```

**select.tcss**


```css
Screen {
    align: center top;
}

Select {
    width: 60;
    margin: 2;
}
```
### Example using Class Method

The following example presents a `Select` created using the `from_values` class method.

**select_from_values_widget.py**


```python
from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Header, Select

LINES = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.""".splitlines()


class SelectApp(App):
    CSS_PATH = "select.tcss"

    def compose(self) -> ComposeResult:
        yield Header()
        yield Select.from_values(LINES)

    @on(Select.Changed)
    def select_changed(self, event: Select.Changed) -> None:
        self.title = str(event.value)


if __name__ == "__main__":
    app = SelectApp()
    app.run()
```

**select.tcss**


```css
Screen {
    align: center top;
}

Select {
    width: 60;
    margin: 2;
}
```
## Blank state

The `Select` widget has an option `allow_blank` for its constructor.
If set to `True`, the widget may be in a state where there is no selection, in which case its value will be the special constant ``Select.BLANK``.
The auxiliary methods ``Select.is_blank`` and ``Select.clear`` provide a convenient way to check if the widget is in this state and to set this state, respectively.

## Type to search

The `Select` widget has a `type_to_search` attribute which allows you to type to move the cursor to a matching option when the widget is expanded. To disable this behavior, set the attribute to `False`.

## Reactive Attributes

| Name       | Type                           | Default          | Description                         |
|------------|--------------------------------|------------------|-------------------------------------|
| `expanded` | `bool`                         | `False`          | True to expand the options overlay. |
| `value`    | `SelectType` \| `_NoSelection` | ``Select.BLANK`` | Current value of the Select.        |

## Messages

-  `Select.Changed`

## Bindings

The Select widget defines the following bindings:

*API reference: `textual.widgets.Select.BINDINGS`*


## Component Classes

This widget has no component classes.

## See also

- [SelectionList](./selection_list.md) - For selecting multiple values from a list
- [OptionList](./option_list.md) - A simpler vertical list of options
- [RadioSet](./radioset.md) - An alternative for choosing one from a set of options
- [Widgets guide](../guide/widgets.md) - How to build and use widgets

---


*API reference: `textual.widgets.Select`*


*API reference: `textual.widgets.select`*
