how to disable text input after user finish input?
now use disabled=True will make input unavailable before user input something.
Thank you.
Anyone have solution for this requirement?
Thank you.
Sorry, your question is not clear to me.
Am I understanding correctly:
a) Your have a text input widget
b) once the user enters something in the input then you want the text input widget to disappear?
My suggestion is this
- Make an empty widget with st.empty
- In the empty widget you just made, create an st.form
- In the form you just made, include a st.text_input widget where the user can enter text.
- In the form you made, you have to include a button. When the button become “submitted” turn your form back into a nice message using something like st.write
So the basic idea is you go from
mywidget = st.empty → (mywidget = st.form + st.text.input) → mywidget = st.write
Does that make sense?
Here’s an alternative to using forms and st.empty:
Solution
import streamlit as st
if "disabled" not in st.session_state:
st.session_state["disabled"] = False
def disable():
st.session_state["disabled"] = True
st.text_input(
"Enter some text",
disabled=st.session_state.disabled,
on_change=disable
)
Output
Best,
Snehan
Thank you very much.
Thank you! But is there a way of, except for re-loading the site, to enable the text again?
You can manually set st.session_state["disabled"] = False
somewhere in your code, or define an enable
function if you want to set it as a callback to some other action.
def enable():
st.session_state["disabled"] = False
Thank you a lot for your very good - and fast response!