Lashtw commited on
Commit
d657b29
·
verified ·
1 Parent(s): 0c3f391

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -6
app.py CHANGED
@@ -41,7 +41,7 @@ st.markdown("""
41
  color: #666;
42
  padding: 5px;
43
  }
44
- /* 頒獎台樣式 */
45
  .podium-container {
46
  display: flex;
47
  justify-content: center;
@@ -90,6 +90,58 @@ st.markdown("""
90
  background-color: rgba(0, 0, 0, 0.5); /* 半透明背景,提升可讀性 */
91
  white-space: pre-line; /* 允許換行 */
92
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  </style>
94
  """, unsafe_allow_html=True)
95
 
@@ -324,9 +376,9 @@ def main():
324
  top_3 = valid_df.head(3)
325
 
326
  if len(top_3) > 0:
 
327
  col1, col2, col3 = st.columns(3) # 創建三列
328
 
329
- # 第二名(如果有)
330
  with col1:
331
  if len(top_3) >= 2:
332
  second = top_3.iloc[1]
@@ -341,7 +393,6 @@ def main():
341
  else:
342
  st.markdown('<div class="podium"><div class="podium-filler" style="height: 30px;"></div><div class="podium-step second"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
343
 
344
- # 第一名(如果有)
345
  with col2:
346
  if len(top_3) >= 1:
347
  first = top_3.iloc[0]
@@ -355,7 +406,6 @@ def main():
355
  else:
356
  st.markdown('<div class="podium"><div class="podium-step first"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
357
 
358
- # 第三名(如果有)
359
  with col3:
360
  if len(top_3) >= 3:
361
  third = top_3.iloc[2]
@@ -369,6 +419,62 @@ def main():
369
  )
370
  else:
371
  st.markdown('<div class="podium"><div class="podium-filler" style="height: 60px;"></div><div class="podium-step third"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
  else:
373
  st.warning("無有效的查詢結果可供顯示頒獎台。")
374
  else:
@@ -380,5 +486,4 @@ def main():
380
  # 添加右下角資訊
381
  st.markdown('<div class="footer">程式設計:新竹縣立精華國中 藍星宇老師</div>', unsafe_allow_html=True)
382
 
383
- if __name__ == "__main__":
384
- main()
 
41
  color: #666;
42
  padding: 5px;
43
  }
44
+ /* 頒獎台樣式(正常顯示) */
45
  .podium-container {
46
  display: flex;
47
  justify-content: center;
 
90
  background-color: rgba(0, 0, 0, 0.5); /* 半透明背景,提升可讀性 */
91
  white-space: pre-line; /* 允許換行 */
92
  }
93
+ /* 全螢幕頒獎台樣式 */
94
+ .podium-fullscreen {
95
+ position: fixed;
96
+ top: 0;
97
+ left: 0;
98
+ width: 100vw;
99
+ height: 100vh;
100
+ background-color: rgba(0, 0, 0, 0.8); /* 半透明黑色背景 */
101
+ display: flex;
102
+ justify-content: center;
103
+ align-items: flex-end;
104
+ z-index: 1000;
105
+ margin: 0;
106
+ padding: 0;
107
+ }
108
+ .podium-fullscreen .podium {
109
+ width: 30vw; /* 按比例放大 */
110
+ margin: 0 2vw;
111
+ }
112
+ .podium-fullscreen .podium-step.first {
113
+ height: 40vh; /* 按比例放大高度 */
114
+ }
115
+ .podium-fullscreen .podium-step.second {
116
+ height: 32vh; /* 按比例放大高度 */
117
+ }
118
+ .podium-fullscreen .podium-step.third {
119
+ height: 24vh; /* 按比例放大高度 */
120
+ }
121
+ .podium-fullscreen .podium-filler.second {
122
+ height: 8vh; /* 填充高度按比例調整 (40vh - 32vh) */
123
+ }
124
+ .podium-fullscreen .podium-filler.third {
125
+ height: 16vh; /* 填充高度按比例調整 (40vh - 24vh) */
126
+ }
127
+ .podium-fullscreen .podium-step {
128
+ font-size: 2rem; /* 放大數字字體 */
129
+ }
130
+ .podium-fullscreen .podium-label {
131
+ font-size: 1.5rem; /* 放大標籤字體 */
132
+ padding: 10px;
133
+ }
134
+ .close-button {
135
+ position: absolute;
136
+ top: 20px;
137
+ right: 20px;
138
+ color: #fff;
139
+ font-size: 1.5rem;
140
+ cursor: pointer;
141
+ background-color: #ff4d4d;
142
+ padding: 5px 10px;
143
+ border-radius: 5px;
144
+ }
145
  </style>
146
  """, unsafe_allow_html=True)
147
 
 
376
  top_3 = valid_df.head(3)
377
 
378
  if len(top_3) > 0:
379
+ # 正常顯示頒獎台
380
  col1, col2, col3 = st.columns(3) # 創建三列
381
 
 
382
  with col1:
383
  if len(top_3) >= 2:
384
  second = top_3.iloc[1]
 
393
  else:
394
  st.markdown('<div class="podium"><div class="podium-filler" style="height: 30px;"></div><div class="podium-step second"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
395
 
 
396
  with col2:
397
  if len(top_3) >= 1:
398
  first = top_3.iloc[0]
 
406
  else:
407
  st.markdown('<div class="podium"><div class="podium-step first"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
408
 
 
409
  with col3:
410
  if len(top_3) >= 3:
411
  third = top_3.iloc[2]
 
419
  )
420
  else:
421
  st.markdown('<div class="podium"><div class="podium-filler" style="height: 60px;"></div><div class="podium-step third"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
422
+
423
+ # 全螢幕顯示按鈕
424
+ if st.button("全螢幕顯示頒獎台"):
425
+ st.session_state.show_fullscreen = True
426
+
427
+ # 全螢幕頒獎台
428
+ if 'show_fullscreen' in st.session_state and st.session_state.show_fullscreen:
429
+ podium_html = '<div class="podium-fullscreen">'
430
+
431
+ # 第二名
432
+ if len(top_3) >= 2:
433
+ second = top_3.iloc[1]
434
+ podium_html += f'''
435
+ <div class="podium">
436
+ <div class="podium-filler second"></div>
437
+ <div class="podium-step second">{int(second["查詢結果"])}</div>
438
+ <div class="podium-label">{second["姓名"]}\n{second["幸運號碼"]}</div>
439
+ </div>
440
+ '''
441
+ else:
442
+ podium_html += '<div class="podium"><div class="podium-filler second"></div><div class="podium-step second"></div><div class="podium-label"></div></div>'
443
+
444
+ # 第一名
445
+ if len(top_3) >= 1:
446
+ first = top_3.iloc[0]
447
+ podium_html += f'''
448
+ <div class="podium">
449
+ <div class="podium-step first">{int(first["查詢結果"])}</div>
450
+ <div class="podium-label">{first["姓名"]}\n{first["幸運號碼"]}</div>
451
+ </div>
452
+ '''
453
+ else:
454
+ podium_html += '<div class="podium"><div class="podium-step first"></div><div class="podium-label"></div></div>'
455
+
456
+ # 第三名
457
+ if len(top_3) >= 3:
458
+ third = top_3.iloc[2]
459
+ podium_html += f'''
460
+ <div class="podium">
461
+ <div class="podium-filler third"></div>
462
+ <div class="podium-step third">{int(third["查詢結果"])}</div>
463
+ <div class="podium-label">{third["姓名"]}\n{third["幸運號碼"]}</div>
464
+ </div>
465
+ '''
466
+ else:
467
+ podium_html += '<div class="podium"><div class="podium-filler third"></div><div class="podium-step third"></div><div class="podium-label"></div></div>'
468
+
469
+ podium_html += '<div class="close-button" onclick="this.parentElement.style.display=\'none\';">關閉</div>'
470
+ podium_html += '</div>'
471
+ st.markdown(podium_html, unsafe_allow_html=True)
472
+
473
+ # 提供關閉按鈕的替代方式(因為 Streamlit 的 onclick 可能不完全可靠)
474
+ if st.button("關閉全螢幕"):
475
+ st.session_state.show_fullscreen = False
476
+ st.rerun()
477
+
478
  else:
479
  st.warning("無有效的查詢結果可供顯示頒獎台。")
480
  else:
 
486
  # 添加右下角資訊
487
  st.markdown('<div class="footer">程式設計:新竹縣立精華國中 藍星宇老師</div>', unsafe_allow_html=True)
488
 
489
+ if