运用python编写随机点名系统

import tkinter as tk
from random import shuffle
from time import sleep
def load_students():
    with open('students.txt', 'r', encoding='utf-8') as file:
        return [line.strip() for line in file]
def select_student(students):
    shuffle(students)
    return students[0]
def update_name():
    global running, selected_name
    if running:
        selected_name = select_student(students)
        name_label.config(text=selected_name)
        root.after(5, update_name)
def start_or_continue():
    global running
    running = True
    update_name()
def stop_update():
    global running
    running = False
root = tk.Tk()
root.geometry("450x300")
root.title("课堂随机点名")
root.config(bg="#F7F7F7")
students = load_students()
selected_name = select_student(students)
name_label = tk.Label(root, text=selected_name, font=("宋体", 36), bg="#F7F7F7",fg="red",pady=60)
name_label.pack(ipadx=150)
running = False
title = tk.Label(root,text="猜猜是哪个倒霉蛋让我点到了", font=("宋体", 20),bg="gray",fg="yellow").place(x=0,y=0,width=450,height=50)
start_button = tk.Button(root, text="开始", font=("宋体", 20), command=start_or_continue)
stop_button = tk.Button(root, text="停止", font=("宋体",20), command=stop_update)
start_button.place(x=20, y=50)
stop_button.place(x=20, y=100)
root.mainloop()

txt文件

效果图

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值