streamlit

Форк
0
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

15
from datetime import date, time
16

17
import streamlit as st
18

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.
22
with st.form("form_1"):
23
    checkbox = st.checkbox("Checkbox", False)
24
    date_input = st.date_input("Date Input", date(2019, 7, 6))
25
    multiselect = st.multiselect("Multiselect", ["foo", "bar"], default=["foo"])
26
    number_input = st.number_input("Number Input")
27
    radio = st.radio("Radio", ["foo", "bar", "baz"])
28
    selectbox = st.selectbox("Selectbox", ["foo", "bar", "baz"])
29
    select_slider = st.select_slider("Select Slider", ["foo", "bar", "baz"])
30
    slider = st.slider("Slider")
31
    text_area = st.text_area("Text Area", value="foo")
32
    text_input = st.text_input("Text Input", value="foo")
33
    time_input = st.time_input("Time Input", time(8, 45))
34
    toggle_input = st.toggle("Toggle Input", value=False)
35
    st.form_submit_button("Submit")
36

37
st.write("Checkbox:", checkbox)
38
st.write("Date Input:", date_input)
39
st.write("Multiselect:", ", ".join(multiselect))
40
st.write("Number Input:", number_input)
41
st.write("Radio:", radio)
42
st.write("Selectbox:", selectbox)
43
st.write("Select Slider:", select_slider)
44
st.write("Slider:", slider)
45
st.write("Text Area:", text_area)
46
st.write("Text Input:", text_input)
47
st.write("Time Input:", time_input)
48
st.write("Toggle Input:", toggle_input)
49

50
with st.form("form_2"):
51
    st.write("Inside form 2")
52
    text_input = st.text_input("Form 2 - Text Input")
53
    col1, col2 = st.columns(2)
54
    col1.form_submit_button(
55
        "Form 2 - Submit (use_container_width, help)",
56
        use_container_width=True,
57
        help="Submit by clicking",
58
    )
59
    col2.form_submit_button(
60
        "Form 2 - Submit 2 (use_container_width)", use_container_width=True
61
    )
62

63

64
with st.form("form_3", border=False):
65
    st.write("Inside form 3 (border=False)")
66
    text_input = st.text_input("Form 3 - Text Input")
67
    st.form_submit_button(
68
        "Form 3 - Submit (use_container_width)",
69
        use_container_width=True,
70
    )
71

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.