I found this code to use images as button.
Using this code, when a user press the button, another tap is opened.
but I wonder how I can get the value(variable) of the pressed button.
For example, when the user pressed the โlionโ image button, the string โlionโ or image name is saved in the variable โimgโ.
Because I want to use the variable โimgโ to code the sidebar function in another tap.
** So, how can get the value of the pressed image button and then use the value to code for changing the sidebar in another tap? **
import streamlit as st
import os
import base64
@st.cache(allow_output_mutation=True)
def get_base64_of_bin_file(bin_file):
with open(bin_file, โrbโ) as f:
data = f.read()
return base64.b64encode(data).decode()
@st.cache(allow_output_mutation=True)
def get_img_with_href(local_img_path, target_url):
img_format = os.path.splitext(local_img_path)[-1].replace(โ.โ, โโ)
bin_str = get_base64_of_bin_file(local_img_path)
html_code = fโโโ
โโโ
return html_code
gif_html = get_img_with_href(โtenor.gifโ, โhttps://docs.streamlit.ioโ)
st.markdown(gif_html, unsafe_allow_html=True)