Different text in the same text block

Is there a way to print different text within the same block over a loop after an interval?
This image below shows an example of what I am trying to convey. The brackets are just for reference.

Hi @Shawn_D_Souza -

Is your goal to keep re-using the same block? Meaning, in your example, just have one of those widgets, with the text constantly updating?

Yes! That is what I am aiming for.

You can do this using st.empty():

https://docs.streamlit.io/en/stable/api.html?highlight=empty#streamlit.empty

If you declare these empty objects outside of a loop, you can use the loop to continuously re-use the same object in place.

1 Like

That’s perfect! Works like a charm.
Here is the sample code for anyone else that might need it in the future:

import time
st.write("## Hello")
b=st.empty()
''' 
Starts at 0 since you don't see the first value
'''
for i in range (0,4):
    b.text(i)
    time.sleep(0.5)