Spaces:
Sleeping
Sleeping
title: st.selectbox | |
slug: /develop/api-reference/widgets/st.selectbox | |
description: st.selectbox displays a select widget. | |
<Autofunction function="streamlit.selectbox" /> | |
<br /> | |
Select widgets can customize how to hide their labels with the `label_visibility` parameter. If "hidden", the label doesn’t show but there is still empty space for it above the widget (equivalent to `label=""`). If "collapsed", both the label and the space are removed. Default is "visible". Select widgets can also be disabled with the `disabled` parameter: | |
```python | |
import streamlit as st | |
# Store the initial value of widgets in session state | |
if "visibility" not in st.session_state: | |
st.session_state.visibility = "visible" | |
st.session_state.disabled = False | |
col1, col2 = st.columns(2) | |
with col1: | |
st.checkbox("Disable selectbox widget", key="disabled") | |
st.radio( | |
"Set selectbox label visibility 👉", | |
key="visibility", | |
options=["visible", "hidden", "collapsed"], | |
) | |
with col2: | |
option = st.selectbox( | |
"How would you like to be contacted?", | |
("Email", "Home phone", "Mobile phone"), | |
label_visibility=st.session_state.visibility, | |
disabled=st.session_state.disabled, | |
) | |
``` | |
<Cloud src="https://doc-selectbox1.streamlit.app/?embed=true" height="300" /> | |