Delete (remove from app screen) Streamlit form (st.form) after feeling

Greetings, guys. I’m building an app and I use a form on it. After user filling the form, I would like to remove it from the screen (remove email, senha and login_button from the screen). Anyone has an idea about how to do that???

with st.form(“login”):
st.markdown("#### Painel de Login")
email = st.text_input(“Email”, placeholder = “Digite aqui seu email”)
senha = st.text_input(“Senha”, placeholder = “Digite aqui sua senha”, type = “password”)
login_button = st.form_submit_button(“Login”)

thanks in advance

You can use an if-statement to show and hide the panel, or you can you st.expander to collapse the area you don’t want to appear anymore.

1 Like

Hi @gabgomesds, welcome to the community!! :wave: :partying_face:

You could use st.empty() to insert a container, create a form with the container, and call the .empty() method on the container to remove the form once the submit button is clicked:

import streamlit as st

placeholder = st.empty()

with placeholder.form("login"):
    st.markdown("#### Painel de Login")
    email = st.text_input("Email", placeholder="Digite aqui seu email")
    senha = st.text_input("Senha", placeholder="Digite aqui sua senha", type="password")
    login_button = st.form_submit_button("Login")

    if login_button:
        placeholder.empty()

Happy Streamlit-ing! :balloon:
Snehan

3 Likes

Thank you @snehankekre and @cualr, both solutions worked like a charm.

i guess there is a typo, should it be:

with placeholder.container():