Lashtw commited on
Commit
29e7e01
·
verified ·
1 Parent(s): 3495107

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -12
app.py CHANGED
@@ -23,19 +23,46 @@ image_data = [
23
  if 'page' not in st.session_state:
24
  st.session_state.page = 0
25
 
26
- # 顯示當前頁面的圖片
27
- st.image(image_data[st.session_state.page]["path"],
28
- caption=image_data[st.session_state.page]["caption"],
29
- use_container_width=True)
 
 
30
 
31
- # 換頁按鈕
32
- col1, col2 = st.columns(2)
33
- with col1:
34
- if st.button("上一頁") and st.session_state.page > 0:
35
- st.session_state.page -= 1
36
- with col2:
37
- if st.button("下一頁") and st.session_state.page < len(image_data) - 1:
38
- st.session_state.page += 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # 顯示當前頁數
41
  st.write(f"頁面: {st.session_state.page + 1} / {len(image_data)}")
 
23
  if 'page' not in st.session_state:
24
  st.session_state.page = 0
25
 
26
+ # 使用容器來控制圖片和按鈕的佈局
27
+ with st.container():
28
+ # 顯示當前頁面的圖片,全屏顯示
29
+ st.image(image_data[st.session_state.page]["path"],
30
+ caption=image_data[st.session_state.page]["caption"],
31
+ use_container_width=True)
32
 
33
+ # 自訂 CSS 樣式,將按鈕浮動在圖片上方
34
+ st.markdown("""
35
+ <style>
36
+ .button-container {
37
+ position: absolute;
38
+ top: 50%;
39
+ width: 100%;
40
+ display: flex;
41
+ justify-content: space-between;
42
+ padding: 0 20px;
43
+ transform: translateY(-50%);
44
+ }
45
+ .stButton > button {
46
+ background-color: rgba(255, 255, 255, 0.7);
47
+ border: none;
48
+ padding: 10px 20px;
49
+ font-size: 16px;
50
+ cursor: pointer;
51
+ }
52
+ .stButton > button:hover {
53
+ background-color: rgba(255, 255, 255, 1);
54
+ }
55
+ </style>
56
+ """, unsafe_allow_html=True)
57
+
58
+ # 在圖片上浮動按鈕
59
+ col1, col2 = st.columns([1, 1]) # 左右分欄
60
+ with col1:
61
+ if st.button("上一頁", key="prev") and st.session_state.page > 0:
62
+ st.session_state.page -= 1
63
+ with col2:
64
+ if st.button("下一頁", key="next") and st.session_state.page < len(image_data) - 1:
65
+ st.session_state.page += 1
66
 
67
  # 顯示當前頁數
68
  st.write(f"頁面: {st.session_state.page + 1} / {len(image_data)}")