Saw this mentioned before on another topic.
Thought i should share my workaround.
Officially Streamlit does not have button change theme support/code support to change the theme but you can do it!
By using a session_state to save the current theme state, you can update the config and update the page by doing st.rerun(), this would only run once since it happens when click the button
if you want multiple themes, you could do a drop down list then button to confirm theme change
This works for me so thought i should share
if st.button(<i use an emote here sun/or moon for light or dark theme> ,help=‘Switch theme’,key=‘switchthemebuttonform’):
selected = st.session_state['themebutton']
if selected=='light':
#st._config.set_option(f'theme.backgroundColor' ,"white" )
st._config.set_option(f'theme.base' ,"dark" )
st._config.set_option(f'theme.backgroundColor' ,"black" )
st._config.set_option(f'theme.primaryColor' ,"#c98bdb" )
st._config.set_option(f'theme.secondaryBackgroundColor' ,"#5591f5" )
st._config.set_option(f'theme.textColor' ,"white" )
#st.markdown(dark, unsafe_allow_html=True)
st.session_state['themebutton'] = 'dark'
else:
st._config.set_option(f'theme.backgroundColor' ,"white" )
st._config.set_option(f'theme.base' ,"light" )
st._config.set_option(f'theme.primaryColor' ,"#5591f5" )
st._config.set_option(f'theme.secondaryBackgroundColor' ,"#82E1D7" )
st._config.set_option(f'theme.textColor' ,"#0a1464")
st.session_state['themebutton'] = 'light'
st.rerun()