【发布时间】:2022-10-18 07:08:40
【问题描述】:
import streamlit as st
import base64
def custom_button(text='button', bgpng=None, height='height: 225px;', width='width: 225px'):
with open (bgpng, 'rb') as img:
convert_img = base64.b64encode(img.read()).decode('utf-8')
background_img = f"background-image: url('data:image/png;base64, {convert_img}');"
st.markdown(f"""
<style>
div.stButton > button:first-child {{
{background_img}
{height}
{width}
}}
</style>""", unsafe_allow_html=True)
button = st.button(text)
return button
button1 = custom_button(text='button', bgpng=r'data\pic1.png')
button2 = custom_button(text='button2', bgpng=r'data\pic2.png')
问题如下,最后一个按钮总是决定其他按钮的属性,在这种情况下是背景图片按钮2确定背景图片按钮1.所以所有按钮都有相同的背景图像。我该如何解决?
【问题讨论】: