當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Streamlit st.empty用法及代碼示例

插入一個單元素容器。

將一個容器插入到您的應用程序中,該容器可用於保存單個元素。例如,這使您可以隨時刪除元素,或一次替換多個元素(使用子多元素容器)。

要在返回的容器上插入/替換/清除元素,您可以使用"with" 表示法或直接在返回的對象上調用方法。請參閱下麵的示例。

函數簽名

st.empty()

例子

使用 "with" 符號就地覆蓋元素:

import time

with st.empty():
     for seconds in range(60):
         st.write(f"⏳ {seconds} seconds have passed")
         time.sleep(1)
     st.write("✔️ 1 minute over!")

替換幾個元素,然後清除它們:

placeholder = st.empty()

# Replace the placeholder with some text:
placeholder.text("Hello")

# Replace the text with a chart:
placeholder.line_chart({"data": [1, 5, 2, 6]})

# Replace the chart with several elements:
with placeholder.container():
     st.write("This is one element")
     st.write("This is another")

# Clear all those elements:
placeholder.empty()

相關用法


注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.empty。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。