Press a button do something then press another button do something else

The button in Streamlit is a stateless interactive element. That is, the code will fire the button_pressed event once, and will not remember it in the subsequent re-runs of the script (because button’s state cannot be saved in the visible UI).

The solution is to use st.checkbox() instead of st.button() because it is capable of maintaining (persisting) the pressed state.

Check this thread for more details:

1 Like