streamlit
70 строк · 2.7 Кб
1# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from datetime import date, time16
17import streamlit as st18
19# Tests all widgets, sans file_uploader, color picker, camera input and data editor,
20# inside a form. These widgets are a lot more complicated to test, and
21# are tested separately within the e2e tests for those components.
22with st.form("form_1"):23checkbox = st.checkbox("Checkbox", False)24date_input = st.date_input("Date Input", date(2019, 7, 6))25multiselect = st.multiselect("Multiselect", ["foo", "bar"], default=["foo"])26number_input = st.number_input("Number Input")27radio = st.radio("Radio", ["foo", "bar", "baz"])28selectbox = st.selectbox("Selectbox", ["foo", "bar", "baz"])29select_slider = st.select_slider("Select Slider", ["foo", "bar", "baz"])30slider = st.slider("Slider")31text_area = st.text_area("Text Area", value="foo")32text_input = st.text_input("Text Input", value="foo")33time_input = st.time_input("Time Input", time(8, 45))34toggle_input = st.toggle("Toggle Input", value=False)35st.form_submit_button("Submit")36
37st.write("Checkbox:", checkbox)38st.write("Date Input:", date_input)39st.write("Multiselect:", ", ".join(multiselect))40st.write("Number Input:", number_input)41st.write("Radio:", radio)42st.write("Selectbox:", selectbox)43st.write("Select Slider:", select_slider)44st.write("Slider:", slider)45st.write("Text Area:", text_area)46st.write("Text Input:", text_input)47st.write("Time Input:", time_input)48st.write("Toggle Input:", toggle_input)49
50with st.form("form_2"):51st.write("Inside form 2")52text_input = st.text_input("Form 2 - Text Input")53col1, col2 = st.columns(2)54col1.form_submit_button(55"Form 2 - Submit (use_container_width, help)",56use_container_width=True,57help="Submit by clicking",58)59col2.form_submit_button(60"Form 2 - Submit 2 (use_container_width)", use_container_width=True61)62
63
64with st.form("form_3", border=False):65st.write("Inside form 3 (border=False)")66text_input = st.text_input("Form 3 - Text Input")67st.form_submit_button(68"Form 3 - Submit (use_container_width)",69use_container_width=True,70)71