郑州网站加工,推广网站挣钱 优帮云,网页设计什么专业能学,自己如何免费制作一个网站一、需求#xff1a;
教师上课常用的点名软件
二、python库安装#xff1a;
openpyxl是Python中用于读写excel文件tkinter是Python中GUI编程非常好用的库#xff0c;而且是标准库#xff0c;不需要安装#xff0c;导入即可使用random库是Python中用于实现随机功能的库
教师上课常用的点名软件
二、python库安装
openpyxl是Python中用于读写excel文件tkinter是Python中GUI编程非常好用的库而且是标准库不需要安装导入即可使用random库是Python中用于实现随机功能的库也是Python的标准库不需要安装导入即可使用
pyinstaller库是Python打包成exe所需要用到的
pip install openpyxlpip install pyinstaller三、代码
import tkinter as tk
from tkinter import *
import random
import time
import openpyxlis_run Falsedef get_students_name():# 学生名单中需要有姓名列workbook openpyxl.load_workbook(学生名单.xlsx)table workbook.activerows, cols table.max_row, table.max_columnname_col 0for col in range(cols):if table.cell(1, col 1).value 姓名:name_col colbreakstudents_name [table.cell(row 1, name_col 1).value for row in range(1, rows)if table.cell(row 1, name_col 1).value is not None]return students_namedef call_lucky_student(var):点名global is_runif is_run:returnis_run Truestart time.time()choice_student(var, start)def choice_student(var, start):global is_runshow_member random.choice(get_students_name())name show_member[0]for zi in show_member[1:]:name zivar.set(name)end time.time()if is_run and end - start 5:window.after(30, choice_student, var, start)else:is_run Falsereturnif __name__ __main__:window tk.Tk()window.resizable(widthFalse, heightFalse)window.geometry(600x400400180)window.title(\t 学 生 点 名 系 统)# 添加显示框var StringVar(value公平 公正 公开)show_label1 Label(window, textvariablevar, justifyleft, anchorCENTER, width16,height2, font楷体 -40 bold, foregroundwhite, bg#1C86EE)show_label1.place(anchortk.NW, x130, y90)# 添加点名按钮button Button(window, text点 名, compoundcenter, font楷体 -30 bold,foreground#9400D3,commandlambda: call_lucky_student(var))button.place(anchorNW, x235, y200)# 显示窗口window.mainloop()四、打包成exe文件
# ss为文件名命令行与文件要在一个文件夹内
pyinstaller -F -w ss.py把学生名单excel表格和软件放在同一个位置打开软件即可
注意学生名单中需要有姓名列
五、效果