Changing selectbox value after pressing button

Hi guys, I’m new here and I love Streamlit!

But… I have a struggle that I wasn’t able to find out the solution for a very long time:

I wish I could change a selectbox value after I press a specific button.

So, let’s take a look into my example code:

import streamlit as st

selectbox = st.selectbox(
     label='test', 
     options=(' ', 'option1')
)

#until select box is with it's default value (i.e, ' '), the code wouldn't do anything.

if selectbox == 'option1':

     # if the user chose the first option, the code would do something

     do_some_stuff() 

     #to confirm the thing, the user must press a button, which will display the message and then get the selectbox to it's default value (i.e., " ")

     if st.button('Confirm!'):

          st.success('Your thing was done.')

          some_function_to_make_selectbox_return_to_default_value() 

          #so my page would be in blank again, with only the selectbox widget to user select.

Did you guys got my question?

3 Likes