自动点名程序效果展现
python加载库
web设置文件路径并加载数据小程序
定义一个随机筛选名字并语音播报的函数swift
定义窗口并展现点名系统
微信

咱们先来看看随机点名小程序最终的实现效果。app

首先加载实现本文功能须要的库。
dom
import tkinter as tkfrom pandas import read_excelfrom random import randintimport osfrom PIL import Imagefrom PIL import ImageTkfrom win32com.client import Dispatch

Python中有能够自动播报语音的库,这样就能够免去咱们一个一个念名字的麻烦啦。ide
#控制播放语音speaker = Dispatch("SAPI.SpVoice")#设置文件存放路径os.chdir(r"F:\微信公众号\Python\46_随机点名系统")
#读入数据data = read_excel(r'学生名单.xls')df1 = list(data['姓名'])df2 = list(data['性别'])

定义一个能够反复调用的随机筛选名字并语音播报的函数。函数
def roll_call(): if len(df1)>0: index_ = randint(0, len(df1) - 1) name = df1.pop(index_) sex = df2.pop(index_) t.insert('insert', f'{name} {sex}\n') # 插入到tkinter界面 speaker.Speak(name) else: speaker.Speak('点名结束')

最后咱们定义一个展现窗口,在窗口中生成一些按钮和名字展现模块,当点击按钮时实现自动点名播报。oop
win = tk.Tk()win.title('欢迎进入点名程序')win.iconbitmap("pikaqiu2.ico")win.geometry('900x900')
# Entry单行文本L = tk.Label(win, bg='lemonchiffon', text = "随机点名小程序", font=("KaiTi", 26), width=55, height=3) # 关键:设置为背景图片L.place(x=0, y=0)
#设置随机点名按钮,退出系统按钮b1 = tk.Button(win, bg='lightblue', text="随机点名", font=("KaiTi", 16), width=20, height=2, command=roll_call)b1.place(x=250, y=200)b2 = tk.Button(win, bg='lightblue', text="退出系统", font=("KaiTi", 16), width=20, height=2, command=win.quit)b2.place(x=550, y=200)
# Entry 单行文本L = tk.Label(win, text="点到的学生名单以下", font=("KaiTi", 18), width=60, height=1)L.place(x=90, y=315)
# 设置多行文本框 宽 高 文本框中字体 选中文字时文字的颜色t = tk.Text(win, width=60, height=100, font=("KaiTi", 24), selectforeground='black') #显示文本t.place(x=90, y=350)
win.mainloop()

扫一扫关注我
19967879837
投稿微信号
本文分享自微信公众号 - 阿黎逸阳的代码(gh_f3910c467dfe)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。