Text_input inside a button doesn't work

I found some problems when I tried to use a text_input inside a button.
This is an example:

import streamlit as st

header = st.header('Text_input APP')
button1 = st.button('Click here')

if button1:
    text = st.text_input('Write some texte', value=' ')
    st.write('Text: ', text)

When I click on the button1 the text_input box appears and I write some text. However, when I press Enter to display what I wrote, the “window” closes and it goes to the app’s initial page.
Is there any way to solve this problem?
Thanks,

The button’s True state happens only when you click it. After the text box edit is applied the app reruns and the button will now be in the False state, so the text box will not display until the button is clicked again. What you want is sticky True/False state between reruns, so you should use a checkbox instead. (Streamlit reruns top to bottom every time a widget value changes.)

1 Like

I tried with a checkbox and it worked perfectly.
Thanks,

1 Like