# How to add checkboxes widget

**URL:** <https://discourse.jupyter.org/t/how-to-add-checkboxes-widget/26256>\
**Category:** Widgets\
**Tags:** how-to, help-wanted\
**Created:** [June 11, 2024, 1:08pm UTC](https://discourse.jupyter.org/t/how-to-add-checkboxes-widget/26256 "2024-06-11T13:08:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EoinDwyer](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/eoindwyer/32/13636_2.png) [@EoinDwyer](https://discourse.jupyter.org/u/EoinDwyer)\
**Post date:** [June 11, 2024, 1:08pm UTC](https://discourse.jupyter.org/t/how-to-add-checkboxes-widget/26256/1 "2024-06-11T13:08:13Z")

</div>

Hi there,

I have a function “**def plot\_multiple(\*args):**” in which a user inputs a tissue type - tissues = {  
“blood”: 0,  
“bone\_cancellous”: 1,  
“bone\_cortical”: 2,  
“brain\_gm”: 3,  
“brain\_wm”: 4,  
“fat\_inf”: 5,  
“fat\_not\_inf”: 6,  
“heart”: 7,  
“kidney”: 8,  
“lens\_cortex”: 9,  
“liver”: 10,  
“lung\_inf”: 11,  
“muscle”: 12,  
“skin\_dry”: 13,  
“skin\_wet”: 14,  
“spleen”: 15,  
“tendon”: 16  
}  
The function plots whichever tissuetypes are input, I want to add a widget such that a user can select multiple tissuetypes and they’ll be plotted rather than them typing them out in the funtion.

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![bollwyvl](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bollwyvl/32/904_2.png) [@bollwyvl](https://discourse.jupyter.org/u/bollwyvl)\
**Post date:** [June 11, 2024, 1:40pm UTC](https://discourse.jupyter.org/t/how-to-add-checkboxes-widget/26256/2 "2024-06-11T13:40:36Z")

</div>

Turns out there isn’t _actually_ a checkboxes widget among the [selection widgets](https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html#selection-widgets), though there are others that will pretty much do this out of the box (with awareness of label vs value), such as [TagsInput](https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html#tagsinput).

If really keen on checkboxes (which have a boolean value) UI:

```auto
from ipywidgets import Checkobox, HBox

# the above, but without "smart" quotes
tissues = {"blood": 0}

# make controls
checkboxes = {k: Checkbox(description=k) for k, v in tissues.items()}

# helper function to map from checked/unchecked value to idx
def selected_tissues() -> list[int]:
    return [tissues[k] for k, v in checkboxes.items() if v.value]

# wire up observers
[
    v.observe(lambda _: plot_multiple(*selected_tissues()), "value")
    for v in checkboxes.values()
]

# show them all
HBox(checkboxes.values())

```
