feat: 添加点名系统基础功能和大转盘点名功能

- 新增 base.py 文件实现基本点名功能
- 新增 plus.py 文件实现大转盘点名功能- 添加学生名单和转盘配置
- 实现随机点名和
This commit is contained in:
sairate 2025-06-22 14:07:36 +08:00
commit b88c8c0802
12 changed files with 300 additions and 0 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

10
.idea/Roll_Call_System.iml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (Roll_Call_System)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,15 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="numpy" />
<item index="1" class="java.lang.String" itemvalue="pyzero" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

12
.idea/material_theme_project_new.xml generated Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="migrated" value="true" />
<option name="pristineConfig" value="false" />
<option name="userId" value="21c1c7ee:193388d497c:-7ff9" />
</MTProjectMetadataState>
</option>
</component>
</project>

7
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10 (Roll_Call_System)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Roll_Call_System)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Roll_Call_System.iml" filepath="$PROJECT_DIR$/.idea/Roll_Call_System.iml" />
</modules>
</component>
</project>

3
READMD.md Normal file
View File

@ -0,0 +1,3 @@
```bash
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
```

44
base.py Normal file
View File

@ -0,0 +1,44 @@
# 导入所需要的库
import tkinter
from tkinter import *
import random
# 创建主窗口
root = Tk()
root.geometry('500x150+300+500')
root.title('点名系统')
bg_image = PhotoImage(file = '点名.png')
bg_label = Label(root, image = bg_image)
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
# 设置全局变量
var = StringVar() # 这个变量用来显示在标签上的名字
names = ["李子傲","周洲","张庭嘉","董明轩"]
# 这个列表存储学生的名字
flag = False # 这个标志用来表示是否正在进行点名
# 定义一个函数,用来进行点名
def roll():
if flag: # 如果正在进行点名,那么显示一个随机的名字
var.set(random.choice(names))
root.after(10, roll) # 在10毫秒后再次调用这个函数
# 定义一个函数,用来切换点名状态
def check():
global flag # 声明我们要使用的是全局变量,而不是创建一个新的局部变量
if flag:
flag = False
else: # 否则,开始点名
flag = True
roll()
# 创建并配置标签和按钮
Label(root, textvariable=var, font=('楷体', 50)).pack()
Button(root, text="开始/停止点名", command=check).pack()
# 启动事件循环
root.mainloop()

186
plus.py Normal file
View File

@ -0,0 +1,186 @@
import tkinter as tk
import random
import math
import time
class RouletteApp:
def __init__(self, root):
self.root = root
self.root.title("大转盘点名系统")
self.root.geometry("600x650")
# 学生名单
self.students = [
"张三", "李四", "王五", "赵六"
]
# 颜色列表
self.colors = [
"#FF9999", "#99FF99", "#9999FF", "#FF99FF"
]
# 创建画布
self.canvas = tk.Canvas(root, width=500, height=500, bg="white")
self.canvas.pack(pady=20)
# 创建按钮
self.spin_button = tk.Button(root, text="开始旋转", command=self.start_spin,
font=("Arial", 14), bg="#4CAF50", fg="white")
self.spin_button.pack(pady=10)
# 创建结果显示标签
self.result_label = tk.Label(root, text="等待旋转...",
font=("Arial", 16, "bold"), fg="#333333")
self.result_label.pack(pady=10)
# 绘制初始转盘
self.draw_roulette()
# 旋转状态变量
self.is_spinning = False
self.spin_speed = 0
self.selected_student = ""
def draw_roulette(self):
"""绘制转盘"""
self.canvas.delete("all") # 清除画布
# 计算每个扇区的角度
angle_per_sector = 360 / len(self.students)
# 绘制扇区
for i in range(len(self.students)):
start_angle = i * angle_per_sector
self.canvas.create_arc(
50, 50, 450, 450,
start=start_angle,
extent=angle_per_sector,
fill=self.colors[i % len(self.colors)],
outline="black"
)
# 添加学生姓名
angle_rad = math.radians(start_angle + angle_per_sector / 2)
text_x = 250 + 150 * math.cos(angle_rad)
text_y = 250 + 150 * math.sin(angle_rad)
self.canvas.create_text(
text_x, text_y,
text=self.students[i],
font=("Arial", 10, "bold"),
angle=start_angle + angle_per_sector / 2
)
# 绘制中心圆
self.canvas.create_oval(240, 240, 260, 260, fill="#FFFFFF", outline="black")
# 绘制指针
self.canvas.create_line(250, 50, 250, 20, width=3, arrow=tk.LAST, fill="red")
self.canvas.create_polygon(240, 50, 260, 50, 250, 70, fill="red")
def start_spin(self):
"""开始旋转转盘"""
if not self.is_spinning:
self.is_spinning = True
self.spin_button.config(state=tk.DISABLED)
self.result_label.config(text="旋转中...")
self.spin_speed = random.uniform(30, 50) # 初始旋转速度
self.spin_roulette()
def spin_roulette(self):
"""旋转转盘动画"""
if self.spin_speed > 0.1:
# 旋转转盘
self.canvas.delete("all")
self.draw_rotated_roulette(self.spin_speed)
# 更新旋转速度(减慢)
self.spin_speed *= 0.97
# 继续旋转
self.root.after(30, self.spin_roulette)
else:
# 旋转结束
self.is_spinning = False
self.spin_button.config(state=tk.NORMAL)
self.select_winner()
def draw_rotated_roulette(self, rotation):
"""绘制旋转后的转盘"""
# 计算每个扇区的角度
angle_per_sector = 360 / len(self.students)
# 绘制扇区
for i in range(len(self.students)):
start_angle = i * angle_per_sector + rotation
self.canvas.create_arc(
50, 50, 450, 450,
start=start_angle,
extent=angle_per_sector,
fill=self.colors[i % len(self.colors)],
outline="black"
)
# 添加学生姓名
angle_rad = math.radians(start_angle + angle_per_sector / 2)
text_x = 250 + 150 * math.cos(angle_rad)
text_y = 250 + 150 * math.sin(angle_rad)
self.canvas.create_text(
text_x, text_y,
text=self.students[i],
font=("Arial", 10, "bold"),
angle=start_angle + angle_per_sector / 2
)
# 绘制中心圆
self.canvas.create_oval(240, 240, 260, 260, fill="#FFFFFF", outline="black")
# 绘制指针
self.canvas.create_line(250, 50, 250, 20, width=3, arrow=tk.LAST, fill="red")
self.canvas.create_polygon(240, 50, 260, 50, 250, 70, fill="red")
def select_winner(self):
"""随机选择一名学生并显示结果"""
self.selected_student = random.choice(self.students)
self.result_label.config(text=f"恭喜!被选中的是: {self.selected_student}", fg="#E91E63")
# 高亮显示选中的学生
self.highlight_winner()
def highlight_winner(self):
"""高亮显示被选中的学生"""
self.draw_roulette() # 先绘制正常转盘
# 找到选中学生的索引
winner_idx = self.students.index(self.selected_student)
angle_per_sector = 360 / len(self.students)
# 绘制高亮扇区
start_angle = winner_idx * angle_per_sector
self.canvas.create_arc(
50, 50, 450, 450,
start=start_angle,
extent=angle_per_sector,
fill="#FFEB3B", # 黄色高亮
outline="black",
width=2
)
# 重新添加学生姓名
angle_rad = math.radians(start_angle + angle_per_sector / 2)
text_x = 250 + 150 * math.cos(angle_rad)
text_y = 250 + 150 * math.sin(angle_rad)
self.canvas.create_text(
text_x, text_y,
text=self.selected_student,
font=("Arial", 10, "bold"),
fill="red", # 红色文本
angle=start_angle + angle_per_sector / 2
)
if __name__ == "__main__":
root = tk.Tk()
app = RouletteApp(root)
root.mainloop()

6
students.json Normal file
View File

@ -0,0 +1,6 @@
[
"周洲",
"张庭嘉",
"李子傲",
"董明轩"
]

BIN
点名.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB