# Button state

**URL:** <https://discuss.streamlit.io/t/button-state/30940>\
**Category:** Using Streamlit\
**Created:** [September 21, 2022, 9:25am UTC](https://discuss.streamlit.io/t/button-state/30940 "2022-09-21T09:25:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabio\_Pasquarella](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/fabio_pasquarella/32/3505_2.png) [@Fabio\_Pasquarella](https://discuss.streamlit.io/u/Fabio_Pasquarella)\
**Post date:** [September 21, 2022, 9:25am UTC](https://discuss.streamlit.io/t/button-state/30940/1 "2022-09-21T09:25:30Z")

</div>

Hello,

I need that once the choice is made, everything does not disappear (I’ve many more widgets to show, that’s just a toy code). I figured it can be done using session\_state, but I couldn’t implement it. Can someone help me? Thank you

```auto
if st.button('choose'):

            choice= st.radio("pick one",
                    ('hello', 'ciao', 'grüez'))
            st.write(choice)

```

---

<div class="post-metadata">

**Author:** ![blackary](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/blackary/32/47725_2.png) [@blackary](https://discuss.streamlit.io/u/blackary)\
**Post date:** [September 21, 2022, 1:35pm UTC](https://discuss.streamlit.io/t/button-state/30940/2 "2022-09-21T13:35:26Z")

</div>

Here’s one way to accomplish it, by essentially making the button into a toggle for an entry in session state, and then checking that session state to decide whether to show the other widgets.

```auto
import streamlit as st

if "button_pressed" not in st.session_state:
    st.session_state["button_pressed"] = False

# Make button function as a toggle.
if st.button("choose"):
    st.session_state["button_pressed"] = not st.session_state["button_pressed"]

if st.session_state["button_pressed"]:
    choice = st.radio("pick one", ("hello", "ciao", "grüez"))
    st.write(choice)

```

---

<div class="post-metadata">

**Author:** ![Fabio\_Pasquarella](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/fabio_pasquarella/32/3505_2.png) [@Fabio\_Pasquarella](https://discuss.streamlit.io/u/Fabio_Pasquarella)\
**Post date:** [September 21, 2022, 6:36pm UTC](https://discuss.streamlit.io/t/button-state/30940/3 "2022-09-21T18:36:59Z")

</div>

> [@blackary](#):
>
> Here’s one way to accomplish it,

thank you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [September 21, 2023, 6:37pm UTC](https://discuss.streamlit.io/t/button-state/30940/4 "2023-09-21T18:37:29Z")

</div>

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
