Python应用开发——30天学习Streamlit Python包进行APP的构建(12)

st.checkbox

显示复选框部件。

Function signature[source]

st.checkbox(label, value=False, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible")

Returns

(bool)

Whether or not the checkbox is checked.

Parameters

label (str)

A short label explaining to the user what this checkbox is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at Supported Functions · KaTeX.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.

For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.

value (bool)

Preselect the checkbox when it first renders. This will be cast to bool internally.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

help (str)

An optional tooltip that gets displayed next to the checkbox.

on_change (callable)

An optional callback invoked when this checkbox's value changes.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

disabled (bool)

An optional boolean, which disables the checkbox if set to True. The default is False.

label_visibility ("visible", "hidden", or "collapsed")

The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".

代码

import streamlit as stagree = st.checkbox("I agree")if agree:st.write("Great!")

 这段代码使用了Streamlit库来创建一个简单的交互式应用程序。首先,它导入了Streamlit库,并创建了一个名为agree的复选框,用于让用户选择是否同意某个条件。然后,它使用if语句来检查用户是否勾选了agree复选框,如果用户勾选了该复选框,就会在应用程序中显示文本"Great!"。

st.color_picker 

显示颜色选择器部件。 

Function signature[source]

st.color_picker(label, value=None, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible")

Returns

(str)

The selected color as a hex string.

Parameters

label (str)

A short label explaining to the user what this input is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at Supported Functions · KaTeX.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.

For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.

value (str)

The hex value of this widget when it first renders. If None, defaults to black.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

help (str)

An optional tooltip that gets displayed next to the color picker.

on_change (callable)

An optional callback invoked when this color_picker's value changes.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

disabled (bool)

An optional boolean, which disables the color picker if set to True. The default is False. This argument can only be supplied by keyword.

label_visibility ("visible", "hidden", or "collapsed")

The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it above the widget (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".

代码

import streamlit as stcolor = st.color_picker("Pick A Color", "#00f900")
st.write("The current color is", color)

 这段代码使用了Streamlit库来创建一个简单的应用程序。首先,它导入了Streamlit库并将其重命名为st。然后,它使用st.color_picker函数创建了一个颜色选择器,用户可以在应用程序中选择颜色。函数的第一个参数是一个文本字符串,用作颜色选择器的标签,第二个参数是一个默认颜色值。接下来,代码使用st.write函数将当前选择的颜色显示在应用程序中。

st.multiselect 

显示多选 widget。

多选窗口小部件一开始是空的。

Function signature[source]

st.multiselect(label, options, default=None, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, max_selections=None, placeholder="Choose an option", disabled=False, label_visibility="visible")

Returns

(list)

A list with the selected options

Parameters

label (str)

A short label explaining to the user what this select widget is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at Supported Functions · KaTeX.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.

For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.

options (Iterable)

Labels for the select options in an Iterable. For example, this can be a list, numpy.ndarray, pandas.Series, pandas.DataFrame, or pandas.Index. For pandas.DataFrame, the first column is used. Each label will be cast to str internally by default.

default (Iterable of V, V, or None)

List of default values. Can also be a single value.

format_func (function)

Function to modify the display of selectbox options. It receives the raw option as an argument and should output the label to be shown for that option. This has no impact on the return value of the multiselect.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

help (str)

An optional tooltip that gets displayed next to the multiselect.

on_change (callable)

An optional callback invoked when this multiselect's value changes.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

max_selections (int)

The max selections that can be selected at a time.

placeholder (str)

A string to display when no options are selected. Defaults to 'Choose an option'.

disabled (bool)

An optional boolean, which disables the multiselect widget if set to True. The default is False. This argument can only be supplied by keyword.

label_visibility ("visible", "hidden", or "collapsed")

The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it above the widget (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".

代码

这段代码使用了Streamlit库来创建一个交互式应用程序。首先,使用`multiselect`函数创建了一个多选框,让用户从一个包含绿色、黄色、红色和蓝色的选项中选择自己喜欢的颜色。初始时,默认选中了黄色和红色两个选项。

接着,使用`write`函数将用户选择的颜色显示在应用程序中。当用户选择完颜色后,选中的颜色将会在屏幕上显示出来。

import streamlit as stoptions = st.multiselect("What are your favorite colors",["Green", "Yellow", "Red", "Blue"],["Yellow", "Red"])st.write("You selected:", options)

st.radio 

显示单选按钮 widget。 

Function signature[source]

st.radio(label, options, index=0, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, horizontal=False, captions=None, label_visibility="visible")

Returns

(any)

The selected option or None if no option is selected.

Parameters

label (str)

A short label explaining to the user what this radio group is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at Supported Functions · KaTeX.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.

For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.

options (Iterable)

Labels for the select options in an Iterable. For example, this can be a list, numpy.ndarray, pandas.Series, pandas.DataFrame, or pandas.Index. For pandas.DataFrame, the first column is used.

Labels can include markdown as described in the label parameter and will be cast to str internally by default.

index (int or None)

The index of the preselected option on first render. If None, will initialize empty and return None until the user selects an option. Defaults to 0 (the first option).

format_func (function)

Function to modify the display of radio options. It receives the raw option as an argument and should output the label to be shown for that option. This has no impact on the return value of the radio.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

help (str)

An optional tooltip that gets displayed next to the radio.

on_change (callable)

An optional callback invoked when this radio's value changes.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

disabled (bool)

An optional boolean, which disables the radio button if set to True. The default is False.

horizontal (bool)

An optional boolean, which orients the radio group horizontally. The default is false (vertical buttons).

captions (iterable of str or None)

A list of captions to show below each radio button. If None (default), no captions are shown.

label_visibility ("visible", "hidden", or "collapsed")

The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it above the widget (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".

代码

import streamlit as stgenre = st.radio("What's your favorite movie genre",[":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"],captions = ["Laugh out loud.", "Get the popcorn.", "Never stop learning."])if genre == ":rainbow[Comedy]":st.write("You selected comedy.")
else:st.write("You didn't select comedy.")

这段代码使用了Streamlit库来创建一个交互式应用程序。首先,它导入了Streamlit库。然后,它使用st.radio函数创建了一个单选框,让用户选择他们喜欢的电影类型。单选框有三个选项,分别是喜剧、戏剧和纪录片。每个选项都有一个标签,用于描述这种类型电影的特点。

接下来,代码检查用户选择的电影类型,并根据选择的结果显示不同的消息。如果用户选择了喜剧,那么会显示"您选择了喜剧。",否则会显示"您没有选择喜剧。"。

要初始化一个空的无线电部件,请使用 "无 "作为索引值:

import streamlit as stgenre = st.radio("What's your favorite movie genre",[":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"],index=None,
)st.write("You selected:", genre)

这段代码使用了Streamlit库来创建一个简单的交互式应用程序。首先,它导入了Streamlit库。然后,它使用`st.radio`函数创建了一个单选按钮,用于让用户选择他们最喜欢的电影类型。单选按钮的标签是"What's your favorite movie genre",选项包括":rainbow[Comedy]"、"***Drama***"和"Documentary :movie_camera:"。最后,它使用`st.write`函数将用户选择的电影类型显示在屏幕上。

部件可以使用 label_visibility 参数自定义隐藏标签的方式。如果参数为 "hidden"(隐藏),则标签不会显示,但在部件上方仍有空位(相当于 label="")。如果为 "collapsed"(折叠),标签和空格都会被移除。默认为 "可见"。单选按钮也可以使用 disabled 参数禁用,并使用 horizontal 参数水平定向:

import streamlit as st# 在会话状态中存储部件的初始值
if "visibility" not in st.session_state:st.session_state.visibility = "visible"st.session_state.disabled = Falsest.session_state.horizontal = Falsecol1, col2 = st.columns(2)with col1:st.checkbox("Disable radio widget", key="disabled")st.checkbox("Orient radio options horizontally", key="horizontal")with col2:st.radio("Set label visibility 👇",["visible", "hidden", "collapsed"],key="visibility",label_visibility=st.session_state.visibility,disabled=st.session_state.disabled,horizontal=st.session_state.horizontal,)

st.selectbox

Function signature[source]

st.selectbox(label, options, index=0, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, placeholder="Choose an option", disabled=False, label_visibility="visible")

Returns

(any)

The selected option or None if no option is selected.

Parameters

label (str)

A short label explaining to the user what this select widget is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at Supported Functions · KaTeX.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.

For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.

options (Iterable)

Labels for the select options in an Iterable. For example, this can be a list, numpy.ndarray, pandas.Series, pandas.DataFrame, or pandas.Index. For pandas.DataFrame, the first column is used. Each label will be cast to str internally by default.

index (int)

The index of the preselected option on first render. If None, will initialize empty and return None until the user selects an option. Defaults to 0 (the first option).

format_func (function)

Function to modify the display of the labels. It receives the option as an argument and its output will be cast to str.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

help (str)

An optional tooltip that gets displayed next to the selectbox.

on_change (callable)

An optional callback invoked when this selectbox's value changes.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

placeholder (str)

A string to display when no options are selected. Defaults to "Choose an option".

disabled (bool)

An optional boolean, which disables the selectbox if set to True. The default is False.

label_visibility ("visible", "hidden", or "collapsed")

The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it above the widget (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".

代码

import streamlit as stoption = st.selectbox("How would you like to be contacted?",("Email", "Home phone", "Mobile phone"))st.write("You selected:", option)

要初始化一个空的选择框,请使用 "无 "作为索引值:

import streamlit as stoption = st.selectbox("How would you like to be contacted?",("Email", "Home phone", "Mobile phone"),index=None,placeholder="Select contact method...",
)st.write("You selected:", option)

这段代码使用了Streamlit库来创建一个交互式应用程序。首先,它创建了一个下拉框(selectbox),让用户选择他们希望如何被联系。下拉框中有三个选项:"Email"、"Home phone"和"Mobile phone"。用户可以在这三个选项中选择一个作为他们的联系方式。如果用户没有进行选择,下拉框会显示占位符"Select contact method..."。

然后,代码使用st.write函数来显示用户选择的联系方式。例如,如果用户选择了"Email",那么st.write函数会显示"You selected: Email"。这里index =none代表默认不指定任何选项,这里会有一个提示,让你选择相应的选项。

选择部件可以使用 label_visibility 参数自定义隐藏标签的方式。如果参数为 "hidden"(隐藏),则标签不显示,但在 widget 上方仍有空位(相当于 label="")。如果为 "collapsed"(折叠),标签和空格都会被移除。默认为 "可见"。也可以使用 disabled 参数禁用选择部件:

import streamlit as st# Store the initial value of widgets in session state
if "visibility" not in st.session_state:st.session_state.visibility = "visible"st.session_state.disabled = Falsecol1, col2 = st.columns(2)with col1:st.checkbox("Disable selectbox widget", key="disabled")st.radio("Set selectbox label visibility 👉",key="visibility",options=["visible", "hidden", "collapsed"],)with col2:option = st.selectbox("How would you like to be contacted?",("Email", "Home phone", "Mobile phone"),label_visibility=st.session_state.visibility,disabled=st.session_state.disabled,)

st.select_slider 

显示滑块 widget,以便从列表中选择项目。

通过传递一个双元素元组或列表作为值,还可以显示一个范围滑块。

st.select_slider 和 st.slider 的区别在于,select_slider 可接受任何数据类型,并接受可迭代的选项集;而 st.slider 仅接受数字或日期/时间数据,并接受范围作为输入。

Function signature[source]

st.select_slider(label, options=(), value=None, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible")

Returns

(any value or tuple of any value)

The current value of the slider widget. The return type will match the data type of the value parameter.

Parameters

label (str)

A short label explaining to the user what this slider is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at Supported Functions · KaTeX.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.

For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.

options (Iterable)

Labels for the select options in an Iterable. For example, this can be a list, numpy.ndarray, pandas.Series, pandas.DataFrame, or pandas.Index. For pandas.DataFrame, the first column is used. Each label will be cast to str internally by default.

value (a supported type or a tuple/list of supported types or None)

The value of the slider when it first renders. If a tuple/list of two values is passed here, then a range slider with those lower and upper bounds is rendered. For example, if set to (1, 10) the slider will have a selectable range between 1 and 10. Defaults to first option.

format_func (function)

Function to modify the display of the labels from the options. argument. It receives the option as an argument and its output will be cast to str.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

help (str)

An optional tooltip that gets displayed next to the select slider.

on_change (callable)

An optional callback invoked when this select_slider's value changes.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

disabled (bool)

An optional boolean, which disables the select slider if set to True. The default is False.

label_visibility ("visible", "hidden", or "collapsed")

The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it above the widget (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".

代码

import streamlit as stcolor = st.select_slider("Select a color of the rainbow",options=["red", "orange", "yellow", "green", "blue", "indigo", "violet"])
st.write("My favorite color is", color)

这段代码使用了Streamlit库来创建一个滑动条,让用户选择彩虹的颜色。用户可以从红、橙、黄、绿、蓝、靛、紫中选择一个颜色。然后代码会显示用户选择的颜色,并输出“我的最喜欢的颜色是”加上用户选择的颜色。下面是一个范围选择滑块的示例:

import streamlit as ststart_color, end_color = st.select_slider("Select a range of color wavelength",options=["red", "orange", "yellow", "green", "blue", "indigo", "violet"],value=("red", "blue"))
st.write("You selected wavelengths between", start_color, "and", end_color)

这段代码使用了Streamlit库来创建一个交互式的滑块,让用户选择颜色的范围。用户可以通过拖动滑块来选择两个颜色之间的范围。代码中首先导入了Streamlit库,然后使用select_slider函数创建了一个滑块,让用户从红、橙、黄、绿、蓝、靛、紫这些选项中选择颜色的范围,默认选择了红色到蓝色的范围。最后,使用write函数将用户选择的颜色范围输出到界面上。

st.toggle

Function signature[source]

st.toggle(label, value=False, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible")

Returns

(bool)

Whether or not the toggle is checked.

Parameters

label (str)

A short label explaining to the user what this toggle is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at Supported Functions · KaTeX.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.

For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.

value (bool)

Preselect the toggle when it first renders. This will be cast to bool internally.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

help (str)

An optional tooltip that gets displayed next to the toggle.

on_change (callable)

An optional callback invoked when this toggle's value changes.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

disabled (bool)

An optional boolean, which disables the toggle if set to True. The default is False.

label_visibility ("visible", "hidden", or "collapsed")

The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".

代码

import streamlit as ston = st.toggle("Activate feature")if on:st.write("Feature activated!")

这段代码使用了Streamlit库来创建一个简单的交互式应用程序。首先,它导入了Streamlit库并将其命名为st。然后,它创建了一个开关(toggle)组件,用于激活或关闭某个功能。用户可以通过单击开关来改变状态。接下来,代码使用if语句来检查开关的状态。如果开关被打开(on为True),则会显示一条消息“Feature activated!”。如果开关被关闭(on为False),则不会显示任何消息。 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/37945.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

昇思25天学习打卡营第04天|数据集 Dataset

数据是深度学习的基础,高质量的数据输入将在整个深度神经网络中起到积极作用。MindSpore提供基于Pipeline的数据引擎,通过数据集(Dataset)和数据变换(Transforms)实现高效的数据预处理。其中Dataset是Pipel…

【QT】设置QTabWidget样式:上、下边线的显示与去除

目录 0.简介 1.环境 2.详细介绍 2.1我的原代码和显示效果 2.2 去掉QTabWidget的边框 2.3 单独留下边线 2.3.1 法一:通过【this->setDocumentMode(true);】设置下边线 2.3.2 通过【QTabWidget::pane】设置下边线 2.4单独设置上边线 2.5 优化界面tab 2.…

STM32的SPI通信

1 SPI协议简介 SPI(Serial Peripheral Interface)协议是由摩托罗拉公司提出的通信协议,即串行外围设备接口,是一种高速全双工的通信总线。它被广泛地使用在ADC、LCD等设备与MCU间,使用于对通信速率要求较高的场合。 …

css 布局出现无法去除的空白

案件介绍&#xff1a;在没有设置任何的css样式的情况下 文字顶部出现无法去除的空白 源代码 <div click"onClick" ><div class"tableTextButton--container"></div><Icon v-if"loading || thisLoading" type"ios-lo…

LeetCode热题100刷题2:283. 移动零、11. 盛最多水的容器、15. 三数之和、42. 接雨水

283. 移动零 挺简单的没啥说的 class Solution { public:void moveZeroes(vector<int>& nums) {//快慢指针 // 快指针负责往前遍历&#xff0c;慢指针记录快指针遍历过的把0撵走的最后一个元素的位置// 然后快指针遍历完之后&#xff0c;慢指针到结尾直接赋0就行in…

LeetCode题练习与总结:环形链表Ⅱ--142

一、题目描述 给定一个链表的头节点 head &#xff0c;返回链表开始入环的第一个节点。 如果链表无环&#xff0c;则返回 null。 如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到达&#xff0c;则链表中存在环。 为了表示给定链表中的环&#xff0c;评测…

数据资产驱动的智能化转型之路:深入解析数据资产在数字化转型中的核心作用,构建全面、智能的数据资产解决方案,助力企业实现智能化运营和决策,引领行业创新

目录 一、引言 二、数据资产在数字化转型中的核心作用 1、决策支持 2、业务优化 3、创新驱动 4、风险管理 三、构建全面、智能的数据资产解决方案 1、数据资产战略规划 2、数据资产采集与整合 3、数据资产治理 4、数据资产分析与挖掘 5、数据资产应用与服务 四、数…

【JVM-01】引言

【JVM-01】引言 1. 什么是JVM&#xff1f;2. JDK、JRE、JVM比较3.常用的JVM有那些4.学习路线 1. 什么是JVM&#xff1f; JVM即 Java Virtual Machine(Java虚拟机)&#xff0c;是Java程序运行的环境(Java 二进制字节码运行环境)。 好处&#xff1a; 一次编写&#xff0c;到处…

【操作系统期末速成】EP05 | 学习笔记(基于五道口一只鸭)

文章目录 一、前言&#x1f680;&#x1f680;&#x1f680;二、正文&#xff1a;☀️☀️☀️2.1 考点十一&#xff1a;死锁的概念与预防2.2 考点十二&#xff1a;死锁的避免一银行间算法2.1 考点十三&#xff1a;死锁的检测与解除 一、前言&#x1f680;&#x1f680;&#x…

【wsl2】升级wsl及ubuntu22.04

y9kp的wsl2 还是用的自己的子网 很久没用wsl2的ubutnu22.04系统 发现无法启动 等待了挺久&#xff0c;启动了 但同时我也在升级wsl中&#xff1a; 升级wsl wsl --update 这个升级是对ubuntu22.04的运行没影响。 apt-get update 然后upgrade wsl2的升级一直在90%多不动 然…

C语言 | Leetcode C语言题解之第206题反转链表

题目&#xff1a; 题解&#xff1a; struct ListNode* reverseList(struct ListNode* head) {if (head NULL || head->next NULL) {return head;}struct ListNode* newHead reverseList(head->next);head->next->next head;head->next NULL;return newHea…

动态应用安全测试 (DAST) 与渗透测试:应用程序安全测试综合指南

二十多年来,Web 应用程序一直是许多企业的支柱,因此其安全性至关重要。 动态应用程序安全测试 (DAST) 和渗透测试对于识别和缓解 Web 应用程序安全中的安全漏洞至关重要。 虽然两者都旨在增强应用程序安全性,但它们在方法、执行和结果方面存在很大差异。 本综合指南将探讨…

正版软件 | R-Studio T80+:数据恢复与取证分析的专业之选

在数据恢复和数字取证领域&#xff0c;专业人士需要一款强大、可靠的工具来应对复杂和高要求的任务。R-Studio T80 由 R-TT 公司推出的新型许可软件&#xff0c;以其年度付费订阅模式&#xff0c;为专家提供了成本效益更高的解决方案。 全面功能&#xff0c;专业服务 R-Studio …

Python自动化测试:web自动化测试——selenium API、unittest框架的使用

web自动化测试2 1. 设计用例的方法——selenium API1.1 基本元素定位1&#xff09;定位单个唯一元素2&#xff09;定位一组元素3&#xff09;定位多窗口/多框架4&#xff09;定位连续层级5&#xff09;定位下拉框6&#xff09;定位div框 1.2 基本操作1.3 等待1.4 浏览器操作1.5…

百度网盘下载速度慢的解决办法

目录 一、背景 二、解决办法 1、点击三个竖点&#xff0c;再点设置 2、点击传输&#xff0c;再点击去开启该功能 3、点击同意&#xff0c;开启优化速率 三、结果 四、备注 一、背景 当你不是百度网盘会员时&#xff0c;你在使用百度网盘下载时&#xff0c;是否下载速度太…

window下git bash设置启动后默认路径进入自己的工程

方法一&#xff1a;更改快捷方式 方法二&#xff1a;修改~/.bashrc

用英文介绍美国总统:Barack Obama First African-American President (2009 – 2017)

Barack Obama: First African-American President (2009 – 2017) Link: https://www.youtube.com/watch?vwHCBI3yypmE&listPLybg94GvOJ9E-ZM1U6PAjgPUmz-V4-Yja&index44 Introduction Barack Obama made history as the first African-American elected to the pre…

Linux开发讲课28---Linux USB 设备驱动模型

Linux 内核源码&#xff1a;include\linux\usb.h Linux 内核源码&#xff1a;drivers\hid\usbhid\usbmouse.c 1. BUS/DEV/DRV 模型 "USB 接口"是逻辑上的 USB 设备&#xff0c;编写的 usb_driver 驱动程序&#xff0c;支持的是"USB 接口"&#xff1a; US…

DDR自学笔记

DDR的技术发展 标准名称 内核时钟(MHz) I/O时钟(MHz) 工作电压(v) 预取位数 突发长度 数据速率(MT/s) 数据带宽(GB/s) 拓扑 SDRAM 100-166 100-166 3.3 1 / 100-166 0.8-1.3 T DDR 133-200 133-200 2.5 2n 2 266-400 2.1-3.2 T DDR2 133-200 266-…

【面试干货】与的区别:位运算符与逻辑运算符的深入探讨

【面试干货】&与&&的区别&#xff1a;位运算符与逻辑运算符的深入探讨 1、&&#xff1a;位运算符2、&&&#xff1a;逻辑运算符3、&与&&的区别 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; & 和 …