• 随机点名可视化界面,记录迟到人员,转exe文件


    随机点名可视化界面,记录迟到人员,转exe文件

    一.介绍

    对于人员采取随机点名

    二.代码

    import datetime
    import random
    from tkinter import *
    from tkinter.filedialog import *
    
    name_lis = []
    print(name_lis)
    root_1 = Tk()
    e = StringVar()
    x = StringVar()
    root_1.title('随机点名')
    
    count = Label(root_1, text='输入点名的人数按回车确定')
    count.grid(row=0, column=0)
    
    enter_1 = Entry(root_1, state='normal', textvariable=e)
    enter_1.grid(row=0, column=1)
    
    enter_1.delete(0, END)
    
    # 初始显示
    Window_1 = Listbox(root_1)
    Window_1.insert(0, '请载入人员名单')
    Window_1.grid(row=1, column=0, sticky=N + S)
    
    Window_2 = Listbox(root_1)
    for name in ['人员名单格式', '请载入人员名单', '一个人员为一行', '文本为TXT格式']:
        Window_2.insert(0, name)
    Window_2.grid(row=1, column=1, sticky=N + S)
    print(name_lis)
    
    
    def enter_chiose(a, enter=enter_1):
        text = enter.get()  # type:str
        if text.isdigit():
            if int(text) <= len(name_lis):
                count_lis = ['点名人数:', f'{text}人']
                Window_1 = Listbox(root_1)
                Window_1.insert(0, count_lis)
                Window_1.grid(row=1, column=0, sticky=N + S)
    
                print(text)
                print(type(text))
                num = int(text)
                a = random.sample(name_lis, num)
                names_lis = ['点名名单']
                print(a)
                if a:
                    names_lis.extend(a)
                Window_2 = Listbox(root_1)
                Window_2.grid(row=1, column=1, sticky=N + S)
                for data in names_lis:
                    Window_2.insert(1, data)
            else:
                lis_1 = ['选择人数超过范围']
                lis_2 = ['选择人数超过范围']
                Window_1 = Listbox(root_1)
                Window_1.insert(0, lis_1)
                Window_1.grid(row=1, column=0, sticky=N + S)
                Window_2 = Listbox(root_1)
                Window_2.insert(0, lis_2)
                Window_2.grid(row=1, column=1, sticky=N + S)
    
        else:
            lis_1 = ['请输入数字']
            lis_2 = ['请输入数字']
            Window_1 = Listbox(root_1)
            Window_1.insert(0, lis_1)
            Window_1.grid(row=1, column=0, sticky=N + S)
            Window_2 = Listbox(root_1)
            Window_2.insert(0, lis_2)
            Window_2.grid(row=1, column=1, sticky=N + S)
    
        enter_1.delete(0, 'end')
    
    
    count_2 = Label(root_1, text='未点到人员记事本')
    count_2.grid(row=0, column=2)
    
    enter_2 = Entry(root_1, state='normal', textvariable=x)
    enter_2.grid(row=1, column=2, sticky=N + S + E + W)
    enter_2.delete(0, END)
    
    
    def b_save(enter=enter_2):
        text = enter.get()
        time = datetime.datetime.now()
        time = str(time).split('.')[0]
        enter.delete(0, 'end')
        data = Label(enter, text=f'上次保存内容
    {time}
    {text}')
        with open('迟到人员.txt', 'a', encoding='utf8') as fa:
            fa.write(f'{time}
    {text}
    ')
        data.grid(row=0, column=0, sticky=N + S + E + W)
    
    
    save_b = Button(root_1, text='保存', command=b_save)
    save_b.grid(row=2, column=2)
    
    enter_1.bind('<Return>', enter_chiose)
    
    
    def b_load():
        fd = LoadFileDialog(root_1)  # 创建打开文件对话框
        filename = fd.go()  # 显示打开文件对话框,并获取选择的文件名称
        if filename:
            try:
                with open(filename, 'r', encoding='utf8') as fr:
                    name_lis.clear()
                    for name in fr:
                        name = name.strip()
                        name_lis.append(name)
            except:
                with open(filename, 'r', encoding='gbk') as fr:
                    name_lis.clear()
                    for name in fr:
                        name = name.strip()
                        name_lis.append(name)
    
            Window_1 = Listbox(root_1)
            Window_1.insert(0, '人员名单')
            Window_1.grid(row=1, column=0, sticky=N + S)
    
            Window_2 = Listbox(root_1)
            for name in name_lis:
                Window_2.insert(0, name)
            Window_2.grid(row=1, column=1, sticky=N + S)
            print(name_lis)
    
    
    load_b = Button(root_1, text='载入人员名单', command=b_load)
    load_b.grid(row=2, column=0)
    
    root_1.mainloop()
    

    三.EXE程序

    压缩文件下载链接:https://github.com/a568972484/Random_roll_call

    exe程序在压缩文件中dist文件中

    四.相关实用文档

    https://blog.csdn.net/weifuliu/article/details/82826643 #生成exe文件
    
    https://www.cnblogs.com/ruo-li-suo-yi/p/7425307.html #grid设置位置参照
    
    https://www.runoob.com/python/python-gui-tkinter.html #菜鸟变成关于tkinter概述
    
    https://www.cnblogs.com/jxxclj/p/9572919.html #参考案例
    
    https://blog.csdn.net/ppdyhappy/article/details/52129612 #打开文件
    
    https://blog.csdn.net/qq_37235798/article/details/82349223 #控件
    
  • 相关阅读:
    计算字符个数
    字符串最后一个单词的长度
    C++面试宝典
    给定三角形ABC和一点P(x,y,z),判断点P是否在ABC内,给出思路并手写代码
    N-皇后问题(N Queens)
    图着色算法详解(Graph Coloring)
    c++学习路线连接
    数据结构--经典排序算法
    5. 最长回文子串
    4. 寻找两个有序数组的中位数
  • 原文地址:https://www.cnblogs.com/pythonywy/p/11213818.html
Copyright © 2020-2023  润新知