Python摇人系统

 图形化界面的随机抽取人系统,把代码中注释解除掉后能指定人选。

import tkinter as tk
import random


class GUI:
    def __init__(self) -> None:
        self.root = tk.Tk()
        self.root.title("课堂随机点名")
        self.root.geometry("600x300")
        self.st = True
        self.interface()

    def interface(self):
        tk.Label(
            self.root,
            text="课堂随机点名",
            font=["SimHei", 20, "bold"],
            width=41,
            height=3,
            foreground="Yellow",
            background="Grey",
        ).grid(row=0, column=0)
        tk.Button(
            self.root, text="开始", font=["SimHei", 20], command=self.show_time
        ).place(x=50, y=120, relwidth=0.2, relheight=0.2)
        tk.Button(
            self.root, text="结束", font=["SimHei", 20], command=self.luck_one
        ).place(x=50, y=200, relwidth=0.2, relheight=0.2)
        tk.Label(
            self.root, text="测试", font=["SimHei", 30, "bold"], foreground="red"
        ).place(x=280, y=140, relwidth=0.3, relheight=0.3)

    def luck_one(self):
        self.st = False

    def show_time(self):
        random.shuffle(name_list)
        self.st = True

        def update_name(index=0):
            if self.st == True:
                if index == len(name_list):
                    index = 0
                name = name_list[index]
                tk.Label(
                    self.root, text=name, font=["SimHei", 30, "bold"], foreground="red"
                ).place(x=280, y=140, relwidth=0.3, relheight=0.3)
                self.root.after(100, update_name, index + 1)
            # else:
            #     tk.Label(
            #         self.root, text="张三", font=["SimHei", 30, "bold"], foreground="red"
            #     ).place(x=280, y=140, relwidth=0.3, relheight=0.3)
        update_name()


if __name__ == "__main__":
    global name_list
    name_list = []
    with open("./Python/data/stu_name.txt", "r", encoding="utf-8") as fp:
        for line in fp:
            name_list.append(line)
    a = GUI()
    a.root.mainloop()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值