St.empty() - How do I see behind user input?

Hello Folks - I am trying to use ‘sessionstate’ along with user input to create a login id, password page. Am using st.empty() to first initialize login and password widgets and then get input from the user.

if session_state.password != 'pwd123':
   title = st.empty()
   title.title("Welcome to this page")
   subtitle = st.empty()
   subtitle.header("Please enter your login details to proceed")
   login = st.empty()
   login.subheader("LOGIN")
   login_id = st.empty()
   login_id.text_input("Name")
   print(login_id)
   pwd_placeholder = st.empty()
   pwd = pwd_placeholder.text_input("Password:", value="", type="password")
   session_state.password = pwd
   if session_state.password == 'pwd123':
       pwd_placeholder.empty()
       title.empty()
       subtitle.empty()
       login.empty()
       login_id.empty()
       main()
   elif session_state.password != '':
       st.error("the password you entered is incorrect")
else:
   main()

I print out the “login_id” to get the name of the user also but whenever I do I get -

<streamlit.delta_generator.DeltaGenerator object at 0x000001EA17C0A588>

Any idea why? I would ideally like to get the “login_id” printed out.

Got the answer. The following will help in the same.

log_name = login_id.text_input("Name")
print(log_name)

Just to be clear, you don’t need the print() statement. The way Streamlit works is to assign the values to whatever you are assigning it to. So in this case, log_name represents the Python str type with the value that the user typed.

Best,
Randy

Yes I agree. Have added the print statement for my benefit to cross-check whether I am seeing the right results.

1 Like