欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-20 20:27:27
随机点名可视化界面,记录迟到人员,转exe文件 一.介绍 对于人员采取随机点名 二.代码 三.EXE程序 压缩文件下载链接:https://github.com/a568972484/Random_roll_call exe程序在压缩文件中dist文件中 四.相关实用文档 ......

随机点名可视化界面,记录迟到人员,转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'上次保存内容\n{time}\n{text}')
    with open('迟到人员.txt', 'a', encoding='utf8') as fa:
        fa.write(f'{time}\n{text}\n')
    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 #控件