I found a solution, using .empty()
You can try this sample code:
import streamlit as st
#You can check .empty documentation
placeholder = st.empty()
with placeholder.container():
st.title("Try")
btn = st.button("try")
#If btn is pressed or True
if btn:
#This would empty everything inside the container
placeholder.empty()
""" ENTER NEW CODE HERE """