插入布局為 side-by-side 列的容器。
插入多個布局 side-by-side 的多元素容器並返回容器對象列表。
要將元素添加到返回的容器中,您可以使用 "with" 表示法(首選)或直接在返回的對象上調用方法。請參閱下麵的示例。
警告
目前,您不能將列放在另一列中。
函數簽名
st.columns(spec)
參數 | 說明 |
---|---|
spec (int or list of numbers) |
|
返回 | 說明 |
(list of containers) | 容器對象的列表。 |
例子
您可以使用 with
表示法將任何元素插入列中:
col1, col2, col3 = st.columns(3)
with col1:
st.header("A cat")
st.image("https://static.streamlit.io/examples/cat.jpg")
with col2:
st.header("A dog")
st.image("https://static.streamlit.io/examples/dog.jpg")
with col3:
st.header("An owl")
st.image("https://static.streamlit.io/examples/owl.jpg")
或者您可以直接在返回的對象中調用方法:
col1, col2 = st.columns([3, 1])
data = np.random.randn(10, 1)
col1.subheader("A wide column with a chart")
col1.line_chart(data)
col2.subheader("A narrow column with the data")
col2.write(data)
相關用法
- Python Streamlit st.color_picker用法及代碼示例
- Python Streamlit st.container用法及代碼示例
- Python Streamlit st.code用法及代碼示例
- Python Streamlit st.caption用法及代碼示例
- Python Streamlit st.cache用法及代碼示例
- Python Streamlit st.camera_input用法及代碼示例
- Python Streamlit st.checkbox用法及代碼示例
- Python Streamlit st.experimental_singleton.clear用法及代碼示例
- Python Streamlit st.bokeh_chart用法及代碼示例
- Python Streamlit st.text_input用法及代碼示例
- Python Streamlit st.area_chart用法及代碼示例
- Python Streamlit st.title用法及代碼示例
- 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.slider用法及代碼示例
- Python Streamlit st.header用法及代碼示例
- Python Streamlit st.form_submit_button用法及代碼示例
- Python Streamlit st.form用法及代碼示例
- Python Streamlit st.plotly_chart用法及代碼示例
- Python Streamlit st.bar_chart用法及代碼示例
- Python Streamlit st.experimental_memo.clear用法及代碼示例
- Python Streamlit st.warning用法及代碼示例
注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.columns。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。