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. 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.
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()
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.