Multi-st.container with an error:"'setIn' cannot be called on an ElementNode"


Hello everyone, I want to create several containers and buttons. Then I click the button and the button recalls the on_click functions to put something in the containers, but I got an error (“‘setIn’ cannot be called on an ElementNode”) when I do that.

Here’s my example code:

import streamlit as st

def b1_fun():
    c1.warning('Hello, this is c1')

def b2_fun():
    c2.warning('Hello, this is c2')

def b3_fun():
    c3.warning('Hello, this is c3')

c1 = st.container()
c2 = st.container()
c3 = st.container()

b1 = st.button('button1', on_click=b1_fun)
b2 = st.button('button2', on_click=b2_fun)
b3 = st.button('button3', on_click=b3_fun)

I click b1, b2 and then b3, but all of them will rise the same error:

If anyone could solve it?
Thanks for reading.

Debug info

  • Streamlit version: 1.18.1
  • Python version: 3.10.8
  • OS version: win11
  • Browser version: microsoft edge 111.0.1660.14 dev or chrome 110.0.5481.178

Hi @qiud19 :wave:

Sharing my reply to a recent similar post: