ProCodebaseProCodebase
  • ModusA Growth OS for your business, on WhatsAppKiosqSell more. Chase less.AI InterviewerAutomated screening & AI-led interviewsXperto AIAI prep companion for candidatesAI Tools HubResume builder, learning paths & more
  • Pre-Vetted DevelopersScreened, scored and ready to interviewAI-Native DevelopersSenior engineers on an hourly basis
  • Services
  • Features
  • Jobs
  • FAQs
Sign inBook a demo
  • Services
  • Features
  • Jobs
  • FAQs
Sign inBook a demo
ProCodebaseProCodebase

ProCodebase Technologies builds AI products for hiring and growth, and ships software for clients as a technical consultancy. We source, screen and deliver pre-vetted developers — so you only interview high-signal candidates.

Products

  • Modus
  • Kiosq
  • AI Interviewer
  • Xperto AI
  • AI Tools Hub

Hire & build

  • Pre-Vetted Developers
  • AI-Native Developers
  • Technical Consultancy
  • MVP Development
  • Features

Resources

  • Articles
  • Topics
  • Certifications
  • Collections
  • Jobs

Company

  • About Us
  • Contact Us
  • Book a Demo
  • FAQs

© 2026 ProCodebase Technologies. All rights reserved.

  • Privacy Policy
  • Terms & Conditions
  • Refund & Cancellation

Level Up Your Skills with Xperto-AI

A multi-AI agent platform that helps you level up your development skills and ace your interview preparation to secure your dream job.

Launch Xperto-AI

Unleashing the Power of Streamlit Widgets

author
Generated by
ProCodebase AI

15/11/2024

python

Sign in to read full article

Introduction to Streamlit Widgets

Streamlit has revolutionized the way we create web applications in Python. At the heart of this revolution are Streamlit widgets - interactive elements that allow users to interact with your app seamlessly. In this blog post, we'll explore various Streamlit widgets and how to use them effectively.

Basic Widgets

Let's start with some fundamental widgets that form the building blocks of any Streamlit app.

Button

The st.button() widget creates a clickable button:

import streamlit as st if st.button('Click me!'): st.write('You clicked the button!')

This simple code creates a button that, when clicked, displays a message.

Checkbox

The st.checkbox() widget creates a toggle-able checkbox:

show_text = st.checkbox('Show text') if show_text: st.write('This text is visible because you checked the box!')

Radio Button

For mutually exclusive options, use st.radio():

option = st.radio('Choose your favorite color:', ('Red', 'Green', 'Blue')) st.write(f'Your favorite color is {option}')

Input Widgets

Streamlit offers various widgets for user input. Let's look at a few:

Text Input

Use st.text_input() for single-line text input:

name = st.text_input('Enter your name:') st.write(f'Hello, {name}!')

Number Input

For numerical input, use st.number_input():

age = st.number_input('Enter your age:', min_value=0, max_value=120, step=1) st.write(f'You are {age} years old')

Slider

Sliders are great for selecting values from a range:

volume = st.slider('Set the volume:', 0, 100, 50) st.write(f'Volume is set to {volume}%')

Select Widgets

For choosing from a list of options, Streamlit provides several widgets:

Selectbox

Use st.selectbox() for dropdown selection:

fruit = st.selectbox('Choose a fruit:', ['Apple', 'Banana', 'Cherry']) st.write(f'You selected: {fruit}')

Multiselect

For multiple selections, use st.multiselect():

options = st.multiselect('Choose your favorite colors:', ['Red', 'Green', 'Blue', 'Yellow']) st.write('You selected:', ', '.join(options))

File Uploader

The st.file_uploader() widget allows users to upload files:

uploaded_file = st.file_uploader('Choose a CSV file', type='csv') if uploaded_file is not None: data = pd.read_csv(uploaded_file) st.write(data)

Date and Time Widgets

Streamlit provides widgets for date and time input:

Date Input

Use st.date_input() for date selection:

date = st.date_input('Select a date:') st.write(f'Selected date: {date}')

Time Input

For time selection, use st.time_input():

time = st.time_input('Set an alarm for:') st.write(f'Alarm set for: {time}')

Advanced Widget Usage

Customizing Widget Appearance

You can customize the appearance of widgets using the key parameter:

st.button('Click me!', key='styled_button', help='This is a custom button')

Conditional Widgets

Create dynamic interfaces by conditionally displaying widgets:

if st.checkbox('Show advanced options'): st.slider('Advanced setting:', 0, 100, 50)

Widgets in Columns

Organize your layout using columns:

col1, col2 = st.columns(2) with col1: st.button('Button 1') with col2: st.button('Button 2')

Handling Widget States

Streamlit maintains widget states across reruns. Use the key parameter to uniquely identify widgets:

count = 0 if st.button('Increment', key='increment_button'): count += 1 st.write(f'Count: {count}')

Conclusion

Streamlit widgets are powerful tools for creating interactive web applications. By combining these widgets creatively, you can build complex, user-friendly interfaces with just a few lines of Python code. Experiment with different widgets, customize their appearance, and create dynamic layouts to take your Streamlit apps to the next level.

Popular tags

pythonstreamlitwidgets

Share now!

Like & bookmark

Related collections

  • Python Basics: Comprehensive Guide

    21/09/2024 · Python

  • Mastering Pandas: From Foundations to Advanced Data Engineering

    25/09/2024 · Python

  • Mastering NLTK for Natural Language Processing

    22/11/2024 · Python

  • TensorFlow Mastery: From Foundations to Frontiers

    06/10/2024 · Python

  • Seaborn: Data Visualization from Basics to Advanced

    06/10/2024 · Python

Related articles

  • Mastering Hyperparameter Tuning with Grid Search in Scikit-learn

    15/11/2024 · Python

  • Visualizing Data Relationships

    06/10/2024 · Python

  • Mastering PyTorch Datasets and DataLoaders

    14/11/2024 · Python

  • Mastering Regression Models in Scikit-learn

    15/11/2024 · Python

  • Mastering Unit Testing and Test Automation in Python

    15/01/2025 · Python

  • Mastering LangGraph

    17/11/2024 · Python

  • Mastering Document Loaders and Text Splitting in LangChain

    26/10/2024 · Python

Popular category

  • Python
  • Generative AI
  • Machine Learning
  • ReactJS
  • System Design