用Python手搓了一个东西

一个小exe

用Python搓了一个点答器,能够实现点答功能
单文件直接运行
目前Version.1,后期添加一些好玩功能(什么时候想到了再加(^ _ ^))

代码

import tkinter as tk
import time

def show_names():
    global running, current_index, selected_name  # 使用全局变量

    running = True  # 设置为运行状态
    current_index = 0  # 初始化当前索引
    show_button.config(text="暂停") # 修改按钮文字为“暂停”
    while running: #  循环条件改为 running
        if current_index >= len(names): #  如果索引超出范围,则重置为0
            current_index = 0
        name = names[current_index]
        result_label.config(text=name)
        window.update()
        time.sleep(0.08)
        current_index += 1

    selected_name = result_label.cget("text") # 获取当前选中的名字

def toggle_pause():
    global running, selected_name, current_index

    running = not running  # 切换运行状态
    if running:
        show_button.config(text="暂停") # 修改按钮文字为“暂停”
        show_names() # 继续点名
    else:
        show_button.config(text="继续") # 修改按钮文字为“开始点名”
        #  暂停时,停留在当前学生
        selected_name = result_label.cget("text")
        

def load_names():
    try:
        with open("names.txt", "r") as f:
            for line in f:
                names.append(line.strip())
    except FileNotFoundError:
        pass

names = []
running = False  # 初始状态为停止
selected_name = "" # 初始选中名字为空
current_index = 0 # 当前学生索引

window = tk.Tk()
window.title("RollCaller")
window.geometry("300x280") # 固定窗口大小

lucky_label = tk.Label(window, text="看看是哪个幸运儿:", font=("Arial Baltic", 16)) # 新增label
lucky_label.pack(pady=(25, 0)) # 放置在顶部,下方填充0

result_label = tk.Label(window, text="就你了", font=("华文行楷", 48)) # 修改label文字
result_label.pack(pady=(30, 0)) # 放置在lucky_label下方

a_label = tk.Label(window, text="========================", font=("Arial Baltic", 16),fg="orange")
a_label.pack(pady=(0,0))

show_button = tk.Button(window, text="开始点名", font=("Arial Baltic", 20),command=toggle_pause) # command绑定toggle_pause
show_button.pack(pady=(20, 0))

lrm_label = tk.Label(window, text="                             By Lumos.R.M.", font=("Arial Baltic", 10),fg="gray")
lrm_label.pack(pady=(7,0))


load_names()

window.mainloop()