一、场景分析
闲来无事,老婆说叫我开发一个课堂点名桌面小程序,给她在课堂随机点名学生问问题。
人生苦短,那就用 Python 给她写一个吧。
二、依赖安装
因为要用到 excel,所以安装两个依赖:
pip install openpyxl
pip install pandas
pip install pyinstaller
三、程序代码
roll-call.py:
import random
import tkinter as tk
import pandas as pd
def excel_read():
# 读取当前路径下学生名单
input_path=r".\学生名单.xlsx"
# 读取 Excel 文件,将其存储在一个DataFrame对象中
df = pd.read_excel(input_path)
first_column_array = df['学生姓名'].values
#print(first_column_array)
return first_column_array
def random_pick_student(students):
# 随机选择一个学生
picked_student = random.choice(students)
return picked_student
def main():
nparray = excel_read()
# 转换为 list
students = nparray.tolist()
def roll_call(label):
# 修改 label text
if len(students) == 0:
label.config(text="所有学生都点过名了")
else:
picked_student = random_pick_student(s

最低0.47元/天 解锁文章
674

被折叠的 条评论
为什么被折叠?



