streamlit_custom_object_html.py
· 223 B · Python
原始文件
import streamlit as st
class MyObject:
def _repr_html_(self):
return "<h1 style='color:blue;'>這是一個自訂物件的 HTML 表示</h1>"
obj = MyObject()
st.write(obj._repr_html_(), unsafe_allow_html=True)
| 1 | import streamlit as st |
| 2 | |
| 3 | class MyObject: |
| 4 | def _repr_html_(self): |
| 5 | return "<h1 style='color:blue;'>這是一個自訂物件的 HTML 表示</h1>" |
| 6 | |
| 7 | obj = MyObject() |
| 8 | st.write(obj._repr_html_(), unsafe_allow_html=True) |
| 9 |