显示一个选择小部件。
函数签名
st.selectbox(label, options, index=0, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False)
参数 | 说明 |
---|---|
label (str) | 一个简短的标签,向用户解释此选择小部件的用途。 |
options (Sequence, numpy.ndarray, pandas.Series, pandas.DataFrame, or pandas.Index) | 选择选项的标签。默认情况下,这将在内部强制转换为 str 。对于 pandas.DataFrame,第一列被选中。 |
index (int) | 第一次渲染时预选选项的索引。 |
format_func (function) | 修改标签显示的函数。它接收选项作为参数,其输出将被强制转换为 str。 |
key (str or int) | 一个可选的字符串或整数,用作小部件的唯一键。如果省略,将根据其内容为小部件生成一个 key 。相同类型的多个小部件可能不共享相同的键。 |
help (str) | 显示在选择框旁边的可选工具提示。 |
on_change (callable) | 当此选择框的值更改时调用的可选回调。 |
args (tuple) | 传递给回调的可选参数元组。 |
kwargs (dict) | 一个可选的 kwargs 字典传递给回调。 |
disabled (bool) | 一个可选的布尔值,如果设置为 True,则禁用选择框。默认值为假。此参数只能由关键字提供。 |
返回 | 说明 |
(any) | 选择的选项 |
示例
option = st.selectbox(
'How would you like to be contacted?',
('Email', 'Home phone', 'Mobile phone'))
st.write('You selected:', option)
相关用法
- Python Streamlit st.select_slider用法及代码示例
- Python Streamlit st.set_page_config用法及代码示例
- Python Streamlit st.slider用法及代码示例
- Python Streamlit st.spinner用法及代码示例
- Python Streamlit st.subheader用法及代码示例
- Python Streamlit st.success用法及代码示例
- Python Streamlit st.snow用法及代码示例
- Python Streamlit st.stop用法及代码示例
- Python Streamlit st.experimental_singleton.clear用法及代码示例
- Python Streamlit st.bokeh_chart用法及代码示例
- Python Streamlit st.caption用法及代码示例
- Python Streamlit st.text_input用法及代码示例
- Python Streamlit st.area_chart用法及代码示例
- Python Streamlit st.title用法及代码示例
- Python Streamlit st.cache用法及代码示例
- Python Streamlit st.experimental_singleton用法及代码示例
- Python Streamlit st.empty用法及代码示例
- Python Streamlit st.error用法及代码示例
- Python Streamlit st.video用法及代码示例
- Python Streamlit st.vega_lite_chart用法及代码示例
- Python Streamlit st.header用法及代码示例
- Python Streamlit st.container用法及代码示例
- Python Streamlit st.form_submit_button用法及代码示例
- Python Streamlit st.form用法及代码示例
- Python Streamlit st.plotly_chart用法及代码示例
注:本文由纯净天空筛选整理自streamlit.io大神的英文原创作品 st.selectbox。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。