Files
xcq/simple_input_display.py

39 lines
1018 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import streamlit as st
st.title("简单的输入展示页面")
# 初始化会话状态
if 'user_input' not in st.session_state:
st.session_state.user_input = ""
if 'display_text' not in st.session_state:
st.session_state.display_text = ""
# 文本输入框
user_input = st.text_input("请输入内容:", value=st.session_state.user_input)
# 更新会话状态中的输入值
st.session_state.user_input = user_input
# 按钮
if st.button("展示"):
st.session_state.display_text = user_input
# 显示内容
if st.session_state.display_text:
st.write("您输入的内容是:")
st.success(st.session_state.display_text)
else:
st.info("请输入内容并点击展示按钮")
# 侧边栏添加说明
with st.sidebar:
st.markdown("### 说明")
st.markdown("""
这是一个简单的Streamlit演示页面包含:
1. 文本输入框
2. 展示按钮
3. 内容显示区域
输入文本后点击"展示"按钮,您输入的内容将会显示在页面上。
""")