Github Readme To Pages Website
Have you ever wanted to create your own professional portfolio website without spending hours writing HTML, CSS, and JavaScript...
Tech Tutorials and Resources Read articleNovember 17, 2026
Building a web application usually involves working with both frontend and backend technologies. We need to design the user interface, handle user interactions, process inputs, and display the results. But what if we could build an interactive web application using Python alone?
This is where Streamlit comes in. Streamlit is an open-source Python framework that makes it easier to create interactive web applications without having to write traditional frontend code using HTML, CSS, or JavaScript.
It is particularly useful for Python projects involving Machine Learning, Data Science, data visualization, dashboards, and other applications where we want to present Python functionality through a simple user interface.
Streamlit – Building interactive applications using Python. (Explore Streamlit)
In this tutorial, I'll walk through the basic features of Streamlit using a simple Python application. We'll explore how to display text, headings, messages, images, buttons, checkboxes, radio buttons, selection boxes, text inputs, and sliders.
We'll also see how to run a Streamlit application locally and how changes in the Python file are reflected in the running application.
"Sometimes, the easiest way to build an interactive application is to use the language you already know."
Streamlit is a Python framework that allows developers to turn Python scripts into interactive web applications. It provides predefined functions for creating different frontend components.
Instead of manually creating web pages and handling frontend interactions, we can use Streamlit functions directly in our Python code.
For example, we can use:
Streamlit is especially useful when working with Machine Learning models because we can create a user interface for a model without building a separate frontend.
For example, we can train a prediction model, take input from a user through Streamlit widgets, pass that input to the model, and display the prediction on the same application.
💡 My tip: If you already know Python and want to build simple interactive applications, Streamlit is a great framework to explore.
Before creating our first Streamlit application, we need Python and a code editor.
I use Visual Studio Code to write and execute Python programs. You can download it from its official website:
Follow these steps to prepare your environment:
Streamlit can be installed using Python's package installer, pip.
pip install streamlit
If you are working inside a virtual environment, activate it before installing the package.
Once the installation is complete, we are ready to create our first Streamlit application.
💡 My tip: Keep your project dependencies organized. For larger projects, using a virtual environment helps avoid conflicts between packages.
Unlike a regular Python script, a Streamlit application is executed using the Streamlit command.
Create a Python file named app.py and add the following code:
import streamlit as st
st.title("My First Streamlit Application")
st.header("Welcome!")
st.text("Hello Everyone!")
Save the file and open the terminal in the project directory.
Execute the following command:
streamlit run app.py
Here, app.py is the name of the Python file containing our Streamlit code.
After executing the command, Streamlit starts a local development server and provides a URL to access the application.
By default, the application runs at:
http://localhost:8501
Open this URL in your browser to view the application.
If the default port is already occupied, Streamlit can use another available port.
One useful feature of Streamlit is its development workflow. When you modify and save the Python file, Streamlit can automatically rerun the application.
This makes it convenient to experiment with different components and see the changes in the browser.
💡 My tip: Keep the terminal running while developing your application. You can edit your Python code and check the updated output in the browser.
Streamlit provides several functions to display different types of text content.
The st.title() function displays the main title of the application.
st.title("Basic App in Python Using Streamlit!!")
We can use headers to organize different sections of the application.
st.header("This is a Header")
st.subheader("This is a Subheader")
The st.text() function displays simple text in the application.
st.text("Hello Everyone!!!")
Streamlit also supports Markdown formatting through the st.markdown() function. This allows us to display formatted text and headings.
st.markdown("# This is a Markdown Header 1")
st.markdown("## This is a Markdown Header 2")
st.markdown("### This is a Markdown Header 3")
Markdown headings can be created using one to six hash symbols, with each level representing a different heading size.
These functions are useful when organizing content and making an application easier to understand.
Streamlit includes predefined functions for displaying different types of status messages.
These messages are useful for communicating the result of an operation or informing users about something happening in the application.
The st.success() function displays a success message.
st.success("For Showing Successful Submission")
The st.info() function displays an informational message.
st.info("Information")
The st.warning() function displays a warning message.
st.warning("This is a Warning")
The st.error() function displays an error message.
st.error("Error Encountered!!")
We can also display exception information using st.exception().
exp = ZeroDivisionError("Trying to divide by Zero")
st.exception(exp)
These functions make it easier to display the status of different operations without creating custom message components.
The st.write() function is a flexible way to display different types of content in a Streamlit application.
For example, we can display a message or even a Python object.
st.write("Writing Python Inbuilt Range Function")
st.write(range(10))
The function can also display many other Python objects, including strings, numbers, lists, dictionaries, and data structures.
This makes it particularly useful when displaying intermediate results or exploring data while developing an application.
We can display images in Streamlit using the st.image() function.
In this example, I used Pillow, a Python imaging library, to open an image file.
First, install Pillow:
pip install Pillow
Import the Image module and load the image:
from PIL import Image
# Loading an image
img = Image.open("Picture-1.jpg")
# Displaying the image
st.image(img, width=200)
Here:
Make sure that the image file is available at the specified path relative to your application.
💡 My tip: Keep images and other supporting files organized inside your project directory so that they can be accessed easily.
A checkbox allows users to select or deselect an option. In Streamlit, we can create one using st.checkbox().
A checkbox returns a Boolean value: True when selected and False when not selected.
if st.checkbox("Show/Hide"):
st.text("Showing the widget")
In this example, the text is displayed only when the checkbox is selected.
This is useful when we want to show or hide additional information based on user interaction.
Radio buttons allow users to select one option from a predefined set of choices.
We can create radio buttons using st.radio().
status = st.radio(
"Select Gender: ",
("Male", "Female")
)
if status == "Male":
st.success("Male")
else:
st.success("Female")
The first argument represents the label of the radio button, while the second argument contains the available options.
The selected option is stored in the status variable.
We can then use conditional statements to perform different actions depending on the selected value.
Streamlit provides selection widgets that allow users to choose one or multiple options.
The st.selectbox() function allows users to select a single option from a list.
hobby = st.selectbox(
"Hobbies: ",
["Dancing", "Reading", "Sports"]
)
st.write("Your hobby is: ", hobby)
The selected hobby is stored in the hobby variable and displayed using st.write().
If we want users to select multiple options, we can use st.multiselect().
prog_lang = st.multiselect(
"Programming Languages: ",
["C", "C++", "PHP", "Python", "R", "Ruby"]
)
st.write(
"Programming Languages you selected are: ",
len(prog_lang),
prog_lang
)
Unlike a regular select box, the multiselect widget returns the selected options as a list.
We can use len(prog_lang) to find the number of selected languages and display the selected values directly.
💡 What I learned: Use selectbox when only one choice is required and multiselect when users should be able to choose several options.
Buttons are among the most commonly used components in interactive applications.
Streamlit provides the st.button() function to create buttons.
We can create a basic button using:
st.button("Click me for no reason")
We can also use the return value of a button to execute a block of code when it is clicked.
if st.button("About"):
st.text("Welcome To My App!!!")
In this example, the welcome message is displayed when the user clicks the About button.
This is useful for actions such as displaying additional information, submitting operations, or triggering application functionality.
Interactive applications often need to collect information from users. For this, Streamlit provides the st.text_input() function.
Let's create a simple input field that accepts a user's name.
name = st.text_input(
"Enter Your name",
"Type Here ..."
)
if st.button("Submit"):
result = name.title()
st.success(result)
Here:
For example, if a user enters "madhurima rawat", the application displays "Madhurima Rawat" after clicking Submit.
This is a simple example of collecting and processing user input in a Streamlit application.
Sliders allow users to select a value from a specified range.
We can create a slider using the st.slider() function.
level = st.slider(
"Select The Level",
1,
5
)
st.text("Selected: {}".format(level))
The first argument represents the slider label, while the second and third arguments specify the minimum and maximum values.
The selected value is stored in the level variable and displayed using st.text().
Sliders are useful for selecting numerical values such as ratings, thresholds, ranges, and model parameters.
Now that we have explored the basic Streamlit components, let's combine them into one application.
The following example brings together the widgets covered in this tutorial.
import streamlit as st
from PIL import Image
# Application title
st.title("Basic App in Python Using Streamlit!!")
# Headers and text
st.header("This is a Header")
st.subheader("This is a Subheader")
st.text("Hello Everyone!!!")
# Markdown
st.markdown("# This is a Markdown Header 1")
st.markdown("## This is a Markdown Header 2")
# Status messages
st.success("Successful Submission")
st.info("Information")
st.warning("This is a Warning")
st.error("Error Encountered!!")
# Display Python objects
st.write("Writing Python Inbuilt Range Function")
st.write(range(10))
# Display an image
img = Image.open("Picture-1.jpg")
st.image(img, width=200)
# Checkbox
if st.checkbox("Show/Hide"):
st.text("Showing the widget")
# Radio button
status = st.radio(
"Select Gender: ",
("Male", "Female")
)
st.success(status)
# Select box
hobby = st.selectbox(
"Hobbies: ",
["Dancing", "Reading", "Sports"]
)
st.write("Your hobby is:", hobby)
# Multiselect
prog_lang = st.multiselect(
"Programming Languages: ",
["C", "C++", "PHP", "Python", "R", "Ruby"]
)
st.write(
"Programming Languages selected:",
len(prog_lang),
prog_lang
)
# Buttons
st.button("Click me for no reason")
if st.button("About"):
st.text("Welcome To My App!!!")
# Text input
name = st.text_input(
"Enter Your name",
"Type Here ..."
)
if st.button("Submit"):
st.success(name.title())
# Slider
level = st.slider("Select The Level", 1, 5)
st.text("Selected: {}".format(level))
Save the code in a file named app.py and execute it using:
streamlit run app.py
Make sure Pillow is installed and Picture-1.jpg is available in the correct location before running the application.
You can now explore the different components, interact with the widgets, and modify the code to customize your application.
💡 My tip: Start with simple components and gradually combine them to build more useful applications.
One of the most interesting uses of Streamlit is deploying Machine Learning projects through an interactive web interface.
A typical Machine Learning project involves training a model, accepting input features, processing those inputs, and generating predictions.
Streamlit can provide the interface for this entire interaction.
For example, a simple prediction application can follow this workflow:
This approach can be used for regression, classification, data analysis, and many other Python-based projects.
In my Streamlit-Programs repository, I have also explored applications involving Linear Regression, Naive Bayes classification, and built-in datasets from scikit-learn.
These examples demonstrate how the same Streamlit workflow can be used for different Python and Machine Learning applications.
Streamlit makes it easier to turn Python scripts into interactive applications. Its predefined components help us display content, collect user input, create widgets, and present results without building a traditional frontend from scratch.
Through this tutorial, we explored how to set up Streamlit, run a local application, display different types of content, work with images, and create interactive components such as checkboxes, radio buttons, selection boxes, buttons, text inputs, and sliders.
These basic components provide a foundation for building more advanced applications, especially when working with Python, Machine Learning, and Data Science projects.
If you are new to Streamlit, I would recommend starting with small applications and experimenting with the available widgets before moving on to larger projects.
"You don't always need a separate frontend to make your Python projects interactive."
Want to explore the complete code? Visit my GitHub repository to check out the Streamlit programs and examples.
Leave a comment 💬
Choose a message to share your thoughts about this article.
Your email app will open with your comment ready to send.