Update app.py
Browse files
app.py
CHANGED
|
@@ -2,3 +2,45 @@ import streamlit as st
|
|
| 2 |
|
| 3 |
x = st.slider('Select a value')
|
| 4 |
st.write(x, 'squared is', x * x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
x = st.slider('Select a value')
|
| 4 |
st.write(x, 'squared is', x * x)
|
| 5 |
+
|
| 6 |
+
# 添加一个按钮
|
| 7 |
+
if st.button("全屏"):
|
| 8 |
+
# 使用 JavaScript 实现全屏功能
|
| 9 |
+
st.markdown(
|
| 10 |
+
"""
|
| 11 |
+
<script>
|
| 12 |
+
function toggleFullScreen() {
|
| 13 |
+
if (!document.fullscreenElement && // alternative standard method
|
| 14 |
+
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) {
|
| 15 |
+
if (document.documentElement.requestFullscreen) {
|
| 16 |
+
document.documentElement.requestFullscreen();
|
| 17 |
+
} else if (document.documentElement.msRequestFullscreen) {
|
| 18 |
+
document.documentElement.msRequestFullscreen();
|
| 19 |
+
} else if (document.documentElement.mozRequestFullScreen) {
|
| 20 |
+
document.documentElement.mozRequestFullScreen();
|
| 21 |
+
} else if (document.documentElement.webkitRequestFullscreen) {
|
| 22 |
+
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
| 23 |
+
}
|
| 24 |
+
} else {
|
| 25 |
+
if (document.exitFullscreen) {
|
| 26 |
+
document.exitFullscreen();
|
| 27 |
+
} else if (document.msExitFullscreen) {
|
| 28 |
+
document.msExitFullscreen();
|
| 29 |
+
} else if (document.mozCancelFullScreen) {
|
| 30 |
+
document.mozCancelFullScreen();
|
| 31 |
+
} else if (document.webkitExitFullscreen) {
|
| 32 |
+
document.webkitExitFullscreen();
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
toggleFullScreen();
|
| 37 |
+
</script>
|
| 38 |
+
""",
|
| 39 |
+
unsafe_allow_html=True
|
| 40 |
+
)
|
| 41 |
+
def click():
|
| 42 |
+
print('hello world')
|
| 43 |
+
st.write("按钮被点击了!")
|
| 44 |
+
return 1
|
| 45 |
+
# 创建一个按钮,并直接指定点击时调用的函数
|
| 46 |
+
st.button("点击我", on_click=click_function)
|