How can ı use st.columns with st.tabs (Streamlit)

I want to work tabs and columns together in streamlit

This is what ım trying to do

with st.tabs("tab1"):
    with st.columns("col1"):
        st.selectbox("City", ["City1", "City2"-])
    with st.columns("col2"):
        st.selectbox("District", ["District1", "District2"])

with st.tabs("tabs2"):
    with st.columns("another_col1"):
         st.selectbox("Another City", ["Another_City1", "Another_City2"])
    with st.columns("another_col2"):
         st.selectbox("Another District", ["Another_District1", "Another_District2"])

If I use it as in the code above, for example, the selectboxes in tab one appear on all tabs.

When I open each tab separately, I want to see different selectboxes in each. How can I do that ?

Try leveraging this setup:

import streamlit as st

tab1, tab2 = st.tabs(["Tab 1", "Tab 2"])

with tab1:
    col1, col2 = st.columns(2)
    with col1:
        st.selectbox("City", ["City1", "City2"])
    with col2:
        st.selectbox("District", ["District1", "District2"])

with tab2:
    col1, col2 = st.columns(2)
    with col1:
        st.selectbox("City", ["AnotherCity1", "AnotherCity2"])
    with col2:
        st.selectbox("District", ["AnotherDistrict1", "AnotherDistrict2"])

Please let me know if this works for you.

1 Like