How to hide element based on if condition

HI,
I have this code :

def hideDATEselector(showBtn,HideDatePicker):
     global x
     global y
     x=showBtn
     y=HideDatePicker

with st.container(key="body-custom-chart"):
     col1, col2= st.columns(2)
     with col1:
        st.header("A cat")
        st.image("https://static.streamlit.io/examples/cat.jpg")

     with col2:
        tab1, tab2, tab3 = st.tabs(["T1", "Test 2", "T3"])
        with tab1:
            if y==True :
                selectedDate = st.date_input("", format="DD/MM/YYYY",label_visibility="collapsed", on_change=hideDATEselector(showBtn=True,HideDatePicker=False))

            elif x==True:
                if st.button(CurrentMonth+ " "+year):
                    st.write("Clicked")
                    hideDATEselector(showBtn=False,HideDatePicker=True)

what I’m looking for is, when I select a date , HideDatePicker is executed to hide the date icker and show the button and when I click the button the hideDATEselector should be executed again to hide the button and show the datepicker .
Could anyone help please to achiave this ?
thanks