Last active
August 27, 2021 12:45
-
-
Save Outsiders17711/262ba0ae5460a2f559b0261c72f592ee to your computer and use it in GitHub Desktop.
A simple Streamlit form that provides three options using checkboxes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import time | |
form = st.sidebar.form("form", clear_on_submit=True) | |
with form: | |
form.write("**`Choose a box :`**") | |
tick_boxes = form.columns(3) | |
col_labels = [col.write(f"`Option {idx + 1}`") for idx, col in enumerate(tick_boxes)] | |
values = [ | |
col.checkbox(f"{idx + 1}", key=f"{idx+1}", value=False) | |
for idx, col in enumerate(tick_boxes) | |
] | |
form.write("") | |
submit = form.form_submit_button("Submit") | |
st.info("**Choose an option using the boxes in the sidebar.**") | |
if submit: | |
list_values = [int(i) for i in values] | |
if sum(list_values) == 0: | |
st.error("**Choose an option!**") | |
time.sleep(1) | |
st.experimental_rerun() | |
elif sum(list_values) > 1: | |
st.error("**You can only tick one box!**") | |
time.sleep(1) | |
st.experimental_rerun() | |
elif sum(list_values) == 1: | |
# ---> | |
# the 'value' variable is the one you then use in if-statements: | |
# >>> if value == 1: | |
value = list_values.index(1) + 1 | |
# ---> | |
st.success(f"**Player choose option << {value} >>.**") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment