A Question about Button Creation

Hi, community,

I am creating a web app that will execute commands in the terminal. While I am figuring out how to do that, I wanted to get UI under control. I have a simple text box followed by a button. On clicking the button, the command gets executed.

Before getting into complex stuff, I thought to create a simple button that displays text on clicking. My question is do I have to use session state? Is there any other way to use onClick?

This is what I have coded so far:

import streamlit as st
import subprocess

def CreateProject(name):

    st.session_state.count = 1
    st.write("Project is created. Name: "+name)

if 'count' not in st.session_state:
    st.session_state.count =0

name = st.text_input("Please provide project name")
btn=st.button("Create project",on_click=CreateProject,args=(name,))
st.write('count=',st.session_state.count)

Hi @Ninad_Pethkar,

Thanks for posting!

You don’t have to use session state to have your app do something when a button is clicked.

For example, you can do:

my_button = st.button("Click me")

if my_button:
   st.write("text I want to display")

Caroline :balloon: