How to clear screen/make blank again?

I want to print some text, then clear the screen, and then print some more text. Is there a command that I can use to accomplish this?

You can use st.empty to keep a placeholder that can be cleaned whenever you want to add new elements.

Here is a unnecessarily convoluted fun example:


import streamlit as st

if "page" not in st.session_state: = 0

def nextpage(): += 1
def restart(): = 0

placeholder = st.empty()
st.button("Next",on_click=nextpage,disabled=( > 3))

if == 0:
    # Replace the placeholder with some text:
    placeholder.text(f"Hello, this is page {}")

elif == 1:
    # Replace the text with a chart:
    placeholder.line_chart({"data": [1, 5, 2, 6]})

elif == 2:
# Replace the chart with several elements:
    with placeholder.container():
        st.write("This is one element")
        st.write("This is another")

elif == 3:
    placeholder.markdown(r"$f(x) = \exp{\left(x^🐈\right)}$")

    with placeholder:
        st.write("This is the end")