Create a new text_input every time I click the button

Hello,

How can I create new text boxes (text_input) by clicking a button. As shown in the reference image, a new text box should get created every time I click the button (something like click to add new row functionality)

@Prabhat_Ratnala
Hi, I just made it come true:

here is the code:

import streamlit as st
import random
import string

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

def add_new_row():
	st.text_input("Please input something",key=random.choice(string.ascii_uppercase)+str(random.randint(0,999999)))

if st.button("Add new row"):
	st.session_state.count += 1
	add_new_row()
	if st.session_state.count>1:
		for i in range(st.session_state.count-1):
			add_new_row()

the most import thing is how to generate different key for the newest text_input
I used the

key=random.choice(string.ascii_uppercase)+str(random.randint(0,999999))

to ensue an unique key will be genreated when button be clicked every time.

How can I save state of each input in the above scenario?

1 Like