Hi @Ronnie_Nolan,
Welcome to the Streamlit Community!
The st.form_submit_button docs say the command has two relevant parameters:
-
on_click
(callable): An optional callback invoked when this button is clicked. -
disabled
(bool): An optional boolean, which disables the button if set to True. The default is False. This argument can only be supplied by keyword.
We can make use of both of them to achieve the behavior you want. In this example:
- We first initialize a session state variable called
disabled
to False and pass that to the form submit button’sdisabled
parameter. - Next, we define a function
disable()
that setsst.session_state.disabled
to True. - Pass the disable function to the
on_click
parameter of the form submit button, so that when the button is clicked, thedisable()
function is executed, and that in-turn disables the button
Code
import streamlit as st
# Disable the submit button after it is clicked
def disable():
st.session_state.disabled = True
# Initialize disabled for form_submit_button to False
if "disabled" not in st.session_state:
st.session_state.disabled = False
with st.form("myform"):
# Assign a key to the widget so it's automatically in session state
name = st.text_input("Enter your name below:", key="name")
submit_button = st.form_submit_button(
"Submit", on_click=disable, disabled=st.session_state.disabled
)
if submit_button:
st.info("You have entered: " + st.session_state.name)
Output
Happy Streamlit-ing!
Snehan