大学课堂点名程序

大学课堂点名程序

目录
在这里插入图片描述
main.py

import tkinter as tk
import pygame
import csv
import random
from datetime import datetime
from tkinter import messagebox
from tkinter import simpledialog
input_data="student1"
def langDu(text):
    print(text)
    pygame.mixer.init()
    pygame.mixer.music.load("./Initialize/Roster/"+text+".mp3")
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        pygame.time.Clock().tick(10)
def langDu2(text):
    print(text)
    pygame.mixer.init()
    pygame.mixer.music.load("./Initialize/RosterSystem/"+text+".wav")
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        pygame.time.Clock().tick(10)

def update_student_name():
    global current_student_index
    global shuffled_student_indices
    if current_student_index < len(student_names):
        student_index = shuffled_student_indices[current_student_index]
        student_name_var.set(student_names[student_index])
        try:
            langDu(student_names[student_index])
        except:
            messagebox.showinfo("提示", student_names[student_index]+"未朗读")
        current_student_index += 1
    else:
        if all(status != "未确定" for status in attendance_status):
            student_name_var.set("点名结束")
        else:
            current_student_index = 0
            update_student_name()

def mark_attendance():
    langDu2("ok")
    global current_student_index
    if current_student_index < len(student_names):
        attendance_status[shuffled_student_indices[current_student_index]] = "已到"
        update_student_name()

def mark_absent():
    langDu2("error")
    global current_student_index
    if current_student_index < len(student_names):
        attendance_status[shuffled_student_indices[current_student_index]] = "未到"
        update_student_name()

def mark_leave():
    langDu2("other3")
    global current_student_index
    if current_student_index < len(student_names):
        attendance_status[shuffled_student_indices[current_student_index]] = "已请假"
        update_student_name()

def mark_whereabouts():
    langDu2("other")
    global current_student_index
    if current_student_index < len(student_names):
        attendance_status[shuffled_student_indices[current_student_index]] = "去向表"
        update_student_name()

def mark_other():
    langDu2("other2")
    global current_student_index
    if current_student_index < len(student_names):
        # 弹出输入框子,获取用户输入的内容
        user_input = tk.simpledialog.askstring("输入内容", "请输入其他信息:")
        if user_input is not None:  # 如果用户输入不为空
            attendance_status[shuffled_student_indices[current_student_index]] = user_input
            update_student_name()

def save_attendance():
    global input_data
    langDu("点名结束")
    langDu2("end")
    current_time = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
    file_name = f'{input_data}_{current_time}.csv'
    with open(file_name, mode='w', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(['学生姓名', '到课情况'])
        for name, status in zip(student_names, attendance_status):
            writer.writerow([name, status])
    messagebox.showinfo("提示", "点名结果保存成功!")

def read_student_list():
    global input_data
    with open("./Initialize/"+input_data+'.csv', mode='r') as file:
        reader = csv.reader(file)
        for row in reader:
            student_names.append(row[0])
            attendance_status.append("未确定")
    global shuffled_student_indices
    shuffled_student_indices = list(range(len(student_names)))
    random.shuffle(shuffled_student_indices)

langDu("开始点名了")

root = tk.Tk()
root.title("点名系统")

student_names = []
attendance_status = []
current_student_index = 0

read_student_list()

student_name_var = tk.StringVar()
student_name_label = tk.Label(root, textvariable=student_name_var, font=('Arial', 200))
student_name_label.pack(pady=20)
update_student_name()

attendance_button = tk.Button(root, text="已到", width=10, command=mark_attendance)
attendance_button.pack(pady=10)

absent_button = tk.Button(root, text="未到", width=10, command=mark_absent)
absent_button.pack(pady=10)

leave_button = tk.Button(root, text="已请假", width=10, command=mark_leave)
leave_button.pack(pady=10)

whereabouts_button = tk.Button(root, text="去向表", width=10, command=mark_whereabouts)
whereabouts_button.pack(pady=10)

other_button = tk.Button(root, text="其他", width=10, command=mark_other)
other_button.pack(pady=10)

save_button = tk.Button(root, text="保存点名结果", width=15, command=save_attendance)
save_button.pack(pady=10)

root.mainloop()

#打包指令:pyinstaller -F -w main.py --hidden-import tkinter --hidden-import pygame --hidden-import csv --hidden-import random --hidden-import datetime

Generate_Name.py

#!/user/bin/env python3
# -*- coding: utf-8 -*-
from gtts import gTTS
import csv
def langDu(text):
    tts = gTTS(text, lang='zh-tw', slow=False)
    tts.save("./Roster/"+text+".mp3")
langDu("点名结束")
langDu("点名开始了")
with open('student1.csv', mode='r') as file:
	reader = csv.reader(file)
	for row in reader:
		print(row[0])
		langDu(row[0])
print("生成完毕")

student1.csv为学生名字手册(一行一个名字)
这个需要自己创建

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值