# 'Select All' on a Streamlit Multiselect

**URL:** <https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799>\
**Category:** Using Streamlit\
**Tags:** multiselect\
**Created:** [February 12, 2021, 4:22pm UTC](https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799 "2021-02-12T16:22:27Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![mathcatsand](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mathcatsand/32/48006_2.png) [@mathcatsand](https://discuss.streamlit.io/u/mathcatsand)\
**Post date:** [June 30, 2025, 8:51pm UTC](https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799/22 "2025-06-30T20:51:24Z")

</div>

FYI to all: You can upvote the feature request to add a “select all” button to `st.multiselect`.

> <https://github.com/streamlit/streamlit/issues/4714>
>
> \### Problem
> 
> I have about twenty options of several \`st.multiselect\`, and someti…mes I need all options except only one. I want to first select all then remove one of them.
> 
> \### Solution
> 
> \*\*MVP:\*\* Maybe create one \`st.multiselect\` means "selected", another means "exclued", but really stupid.
> 
> \---
> 
> Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
> 
> \*\*If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.\*\*
> 
> !\[Views\](https://api.views-badge.org/badge/st-issue-4714)

---

<div class="post-metadata">

**Author:** ![nishesh\_awale](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@nishesh\_awale](https://discuss.streamlit.io/u/nishesh_awale)\
**Post date:** [July 2, 2025, 5:08pm UTC](https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799/23 "2025-07-02T17:08:21Z")

</div>

Thanks @mathcatsand for the answer. I have modified your code slightly to include the if and else block in both “update checkbox” and “update\_multiselect” function. My application sometimes take a few minutes to run and to simulate that I have use time.sleep() in the code below. The problem is when all three options have been selected in multiselect and if I remove two of those options quickly while the app is still running, then all the options get cleared out from the multiselect instead of just clearing out the two options that were removed. But if I do the same thing after commenting out the line that contains time.sleep(), then it works as expected. Could you let me know why Streamlit behaves differently in the two cases and how can I resolve this?

```auto
import streamlit as st
import time

# Initialize the vlue of both widgets through session state
if "multiselect_key" not in st.session_state:
    st.session_state.multiselect_key = []
    st.session_state.all = False

def update_checkbox():
    if len(st.session_state.multiselect_key) == 3: # if all are selected
        st.session_state.all = True # Force checkbox to True (and disable it)
    else:
        st.session_state.all = False
    time.sleep(3) # Comment out this line to get different behavior

def update_multiselect():
    if st.session_state.all:
        st.session_state.multiselect_key = ["A", "B", "C"]
    else:
        st.session_state.multiselect_key = []

st.multiselect(
    "Select items",
    options=["A", "B", "C"],
    key="multiselect_key",
    on_change=update_checkbox,
    placeholder="All"
)
st.checkbox("Select All", key="all", on_change=update_multiselect)

```

---

<div class="post-metadata">

**Author:** ![mathcatsand](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mathcatsand/32/48006_2.png) [@mathcatsand](https://discuss.streamlit.io/u/mathcatsand)\
**Post date:** [July 2, 2025, 6:14pm UTC](https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799/24 "2025-07-02T18:14:42Z")

</div>

> [@nishesh\_awale](#):
>
> ```auto
> else:
> st.session_state.multiselect_key = []
> 
> ```

This doesn’t happen if you remove this. I think this is a bug.

If you go from all and remove two in succession, the first removal starts its callback quickly enough to set `st.session_state.all=False`. When you click the next one, the callback is still running, and because the checkbox value was changed in that incomplete run, Streamlit is registering a “change” to the checkbox and running the callback. Had the first run completed before removing the second option, Streamlit doesn’t get confused about a misread that the checkbox “changed” from the user.

---

<div class="post-metadata">

**Author:** ![mathcatsand](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mathcatsand/32/48006_2.png) [@mathcatsand](https://discuss.streamlit.io/u/mathcatsand)\
**Post date:** [July 2, 2025, 6:15pm UTC](https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799/25 "2025-07-02T18:15:54Z")

</div>

The bug report exists here: [on\_change callback is triggered without user-interaction on in-script delays · Issue #10102 · streamlit/streamlit · GitHub](https://github.com/streamlit/streamlit/issues/10102)

---

<div class="post-metadata">

**Author:** ![nishesh\_awale](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@nishesh\_awale](https://discuss.streamlit.io/u/nishesh_awale)\
**Post date:** [July 2, 2025, 8:49pm UTC](https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799/26 "2025-07-02T20:49:05Z")

</div>

Thanks @mathcatsand for the clarification. I removed the else block and use the “disabled” parameter based on the value of st.session\_state.all. This workaround is functioning well for now. Looking forward to this “Select All” feature being natively supported on Streamlit.

[https://github.com/streamlit/streamlit/pull/11820](https://github.com/streamlit/streamlit/pull/11820)

[Previous page](https://discuss.streamlit.io/t/select-all-on-a-streamlit-multiselect/9799.md?page=1)
