Python上课点名神器
.因为上网课,做直播课,想吸引学生来好好上课,所以做了个点名器。代码参考了仇鼎凯老师课上的内容,在此表示感谢。我加上了语音播报和背景音乐。
第一次发表文章,请大家多多包涵。
使用时需要准备学生的名单TXT文件
import random
import easygui
import turtle
import time
import pygame
import pyttsx3
import pyttsx3.drivers
import pyttsx3.drivers.sapi5
engine = pyttsx3.init() # 初始化
rate = engine.getProperty('rate')
engine.setProperty('rate', rate - 55)
students= []
# students = ["tom", "jerry", "jack", "bob"]
# count = len(students)
file = open("student.txt")
for stu_name in file.readlines():
students.append(stu_name.strip())
count= len(students)
while True:
btn = easygui.buttonbox(" 点名请按开始,退出请按退出", "随机点名系统", ("开始", "退出"))
if btn=="开始":
#背景音效
pygame.init()
music = pygame.mixer.music.load('bg.mp3')
pygame.mixer.music.play(-1, 100)
screen = pygame.display.set_mode((1, 1))
rand = random.randint(0, count-1)
turtle.goto(0,0)
turtle.up()
turtle.hideturtle()
#easygui.msgbox(students[rand], "Roll")
for i in range(50):
turtle.clear()
turtle.write(students[(i+rand)%count],move=False,align="center",font=("Arial",40,"normal"))
time.sleep(0.1)
turtle.goto(0,80)
turtle.write("请答题", move=False, align="center", font=("Arial", 40, "normal"))
#背景音乐停止
pygame.mixer.music.stop()
txt = students[(i+rand)%count]
engine.say("请答题"+txt)
engine.runAndWait() # 运行并且等待
students.pop((i+rand)%count)
count=len(students)
else:
break