sairate b88c8c0802 feat: 添加点名系统基础功能和大转盘点名功能
- 新增 base.py 文件实现基本点名功能
- 新增 plus.py 文件实现大转盘点名功能- 添加学生名单和转盘配置
- 实现随机点名和
2025-06-22 14:07:36 +08:00

45 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 导入所需要的库
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()