Streamlit auto refreshing problem

My code never prints “ok”. When the ready button is clicked, the image does disappear though.

I think this might be related to how streamlit continuously refreshes/updates. Not sure how to fix it beyond that though!

I added the form part because I thought that could prevent the autorefreshing. Removing it doesn’t change anything.

hi @catrazzy ,

Did you try using st.write instead of print?

Yes! It doesn’t look like the issue though. I’m planning to look into using session states instead (:

Hi @catrazzy, you could do something like:

import streamlit as st
import time as tm

if "btn_state" not in st.session_state: st.session_state.btn_state = False

st.session_state.btn_state = st.button("Record")
while not st.session_state.btn_state: tm.sleep(0.01)

You could (a) read up on session_state and (b) wrap the “while…” statement with a try-except for any error processing, if needed.