Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,35 @@
|
|
| 1 |
-
import
|
| 2 |
import random
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
inputs=gr.Number(label="班級座號的最大值", default=35, precision=0),
|
| 14 |
-
outputs="text",
|
| 15 |
-
title="抽籤系統",
|
| 16 |
-
description="輸入班級座號的最大值,然後點擊按鈕進行抽籤。"
|
| 17 |
-
)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
| 21 |
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tkinter as tk
|
| 2 |
import random
|
| 3 |
|
| 4 |
+
def draw_number():
|
| 5 |
+
try:
|
| 6 |
+
max_number = int(entry_max.get())
|
| 7 |
+
if max_number <= 0:
|
| 8 |
+
result_label.config(text="請輸入正確的座號最大值")
|
| 9 |
+
return
|
| 10 |
+
drawn_number = random.randint(1, max_number)
|
| 11 |
+
result_label.config(text=f"抽中的號碼是:{drawn_number}")
|
| 12 |
+
except ValueError:
|
| 13 |
+
result_label.config(text="請輸入有效的數字")
|
| 14 |
|
| 15 |
+
# 創建主窗口
|
| 16 |
+
root = tk.Tk()
|
| 17 |
+
root.title("抽籤系統")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# 最大值輸入框
|
| 20 |
+
label_max = tk.Label(root, text="請輸入座號最大值:")
|
| 21 |
+
label_max.pack()
|
| 22 |
|
| 23 |
+
entry_max = tk.Entry(root)
|
| 24 |
+
entry_max.pack()
|
| 25 |
|
| 26 |
+
# 抽籤按鈕
|
| 27 |
+
draw_button = tk.Button(root, text="抽籤", command=draw_number)
|
| 28 |
+
draw_button.pack()
|
| 29 |
+
|
| 30 |
+
# 結果顯示
|
| 31 |
+
result_label = tk.Label(root, text="")
|
| 32 |
+
result_label.pack()
|
| 33 |
+
|
| 34 |
+
# 啟動主循環
|
| 35 |
+
root.mainloop()
|