How to create a container with a button if click this button remove all the container elements

how to create a container with a button if click this button remove all the container elements.

In case it’s relevant, there is an expander element that might be helpful.

Otherwise, you can put the container inside a conditional.

if 'hide' not in st.session_state:
    st.session_state.hide = False

def show_hide():
    st.session_state.hide = not st.session_state.hide

st.button('Show/Hide', on_click=show_hide)

if st.session_state.hide:
    secret = st.container()
    with secret:

Thanks mathcatsand, but I have another doubt related to this. suppose I create a form and click the form button show form result but not show form.

if I click form button clear every things in this page and show only form result.

Here’s an expansion of my example. Is this what you mean?

if 'input' not in st.session_state:
    st.session_state.input = True

def show_result():
    # Copy info from widgets into a different key in session state to avoid 
    # deletion when the widgets disappear
    st.session_state.result = (st.session_state.thing, st.session_state.count)
    st.session_state.input = False

def reset():
    st.session_state.input = True

if st.session_state.input:
    # Show input widgets if in input mode
    st.text_input('Name a thing', key='thing')
    st.number_input('Count them',key='count',step=1)
    st.button('Show Result', on_click=show_result) # Callback changes it to result mode
   # Otherwise, not in input mode, so show result
    st.write(f'There are {st.session_state.result[1]} {st.session_state.result[0]}s.')
    st.button('Reset', on_click=reset) # Callback changes it to input mode

thank you, seriously it really really helpful, Where are you from and what is your work designation.

1 Like

Glad to help. I added my linkedin to my profile for you.