Text is not displaying

I am trying to create simple streamlit app which capture the user input using two buttons one is to open a text input and another one to display the text

After clicking the second button instead of displaying text its closing automatically

Any idea would be appreciated

import streamlit as st

st.title("Main Page")


if st.button("My Button"):
    my_input = st.text_input("Input a text here")
    submit = st.button("Submit")
    if submit:
        st.text("You have entered: ", my_input)

Buttons always return to False so it’s not a good idea to have other widgets afterwards.

2 Likes

Is there way to center align the submit button

One option for center aligning is to use columns. This adds 3 columns, and puts the button in the center column.

import streamlit as st

st.title("Main Page")


if st.button("My Button"):
    my_input = st.text_input("Input a text here")
    _, center, _ = st.columns([3, 1, 3])
    submit = center.button("Submit")
    if submit:
        st.write("You have entered: ", my_input)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.