Do I have to name the selectboxes differently?

Hello!
If I want to assign variable values via selectboxes in different py documents for the same projects, do I have to name the selectboxes differently?
e.g.
01.py
user_language01 = st.selectbox01
02.py
user_language02 = st.selectbox02

or could this all be
01.py
user_language01 = st.selectbox
02.py
user_language02 = st.selectbox

Thanks!

user_language01 = st.selectbox01 would raise NameError, wouldnโ€™t it?

Thanks. I see since I added the selectbox in other documents a conflict, it only passes the language parameter correctly in the first document, but not in the other documents. so I thought maybe it could also be the name of the checkbox. sorry, Iโ€™m just starting with python.

tl;dr

You only need to name the variables differently and differentiate the name within the label of the selectbox but the โ€œst.selecboxโ€ is a streamlit function name, you canโ€™t change it.

So again, the answer is the second option you mentioned;

or could this all be
01.py
user_language01 = st.selectbox
02.py
user_language02 = st.selectbox

Code sample


import streamlit as st

def main():
    st.title("Selectboxes examples")

    # this is just so i can display the st.info on top of the selectbox 
    info_slot1 = st.empty()
    # selectbox 1
    user_language01 = st.selectbox("Select Your First Language", ["Japanese", "Arabic", "Portuguese"])

    # displaying the selected option using st.info()
    info_slot1.info("You selected Option: " + user_language01)

    # this is just a divider I added due to the dropdown menu of the selectbox covering the selectbox beneth it
    st.markdown('<div style="margin-block: 60px; text-align: center;">----------</div>', unsafe_allow_html=True)

    info_slot2 = st.empty()
    # selectbox 2
    user_language02 = st.selectbox("Select Your Second Language", ["Italian", "English", "Maltese"])

    # you can also just display it using st.write or something else
    info_slot2.info("You selected Option: " + user_language02)

if __name__ == "__main__":
    main()

Result

streamlitselecbox

2 Likes

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