| 函数签名[source] | |
|---|---|
st.toast(body, *, icon=None) | |
| 参数 | |
body (str) | 要显示为GitHub风格的Markdown的字符串。语法信息可以在以下链接找到:https://github.github.com/gfm。 有关其他支持的Markdown指令,请参见st.markdown的body参数。 |
icon (str, None) | 一个可选的emoji或图标,显示在警报旁边。如果icon是None(默认),则不显示图标。如果icon是一个字符串,以下选项是有效的:
|
示例
import streamlit as st
st.toast('Your edited image was saved!', icon='😍')
当生成多个toast时,它们会堆叠在一起。将鼠标悬停在toast上会阻止它消失。当悬停结束时,toast将在四秒后消失。
import streamlit as st
import time
if st.button('Three cheers'):
st.toast('Hip!')
time.sleep(.5)
st.toast('Hip!')
time.sleep(.5)
st.toast('Hooray!', icon='🎉')
Toast 消息也可以更新。将 st.toast(my_message) 赋值给一个变量,并使用 .toast() 方法来更新它。注意:如果 toast 已经消失或被关闭,更新将不会被看到。
import streamlit as st
import time
def cook_breakfast():
msg = st.toast('Gathering ingredients...')
time.sleep(1)
msg.toast('Cooking...')
time.sleep(1)
msg.toast('Ready!', icon = "🥞")
if st.button('Cook breakfast'):
cook_breakfast()
还有问题吗?
我们的 论坛 充满了有用的信息和Streamlit专家。