赞
踩
streamlit==1.29.0
代码:
- import base64
- import streamlit as st
-
- def sidebar_bg(side_bg):
-
- side_bg_ext = 'png'
-
- st.markdown(
- f"""
- <style>
- [data-testid="stSidebar"] > div:first-child {{
- background: url(data:image/{side_bg_ext};base64,{base64.b64encode(open(side_bg, "rb").read()).decode()});
- }}
- </style>
- """,
- unsafe_allow_html=True,
- )
-
- #调用
- sidebar_bg('./pics/background1.jpg')
效果:
代码:
- def main_bg(main_bg):
- main_bg_ext = "png"
- st.markdown(
- f"""
- <style>
- .stApp {{
- background: url(data:image/{main_bg_ext};base64,{base64.b64encode(open(main_bg, "rb").read()).decode()});
- background-size: cover
- }}
- </style>
- """,
- unsafe_allow_html=True
- )
-
- #调用
- main_bg('./pics/background.jpg')
效果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。