Ask the community or our support engineers for answers to questions.
is that a way to overwrite or clear user input value by click a button?
for example, by click the button, clear the text input value.
Ask the community or our support engineers for answers to questions.
is that a way to overwrite or clear user input value by click a button?
Yes, you can store the value of the click and if its true, set the value of the text input to blank.
import streamlit as st
placeholder = st.empty()
input = placeholder.text_input('text')
click_clear = st.button('clear text input', key=1)
if click_clear:
input = placeholder.text_input('text', value='', key=1)
This works for me. Does it answer your q?
Dinesh
it works, thanks. another trick in streamlit. it is amazing. Thanks.
In your case, I think you can use “st.form” and “st.form_submit_button”, the former with the parameter: clear_on_submit = True (st.form - Streamlit Docs, st.form_submit_button - Streamlit Docs)
Why are the keys for button and text_input equal? Does this create a link of some kind between the objects?
Also, help me understand how does do placeholder work in this case: if it didn’t exist we would get a DuplicateWidget exception for the text_input, is that right?
@victorccaldas
that code is old. I suggest using the st.form and st.form_submit_button as jgcaceresr suggested.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.