随机点名器

 

import random
from tkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
from threading import Timer
import time


text = Tk()
text.title('随机点名表')
text.geometry('1200x500')
text.resizable(width=False,height=False)

z_wenjian_name=[]

list_e = Listbox(text,selectmode=MULTIPLE)
list_e.place(width=100,height=300)
gunlun = Scrollbar(list_e,command=list_e.yview)
gunlun.pack(side=RIGHT,fill=Y)
list_e.config(yscrollcommand=gunlun.set)
list_e.place(x=860,y=100)

list_e2 = Listbox(text,selectmode=MULTIPLE)
list_e2.place(width=100,height=300)
gunlun2 = Scrollbar(list_e2,command=list_e2.yview)
gunlun2.pack(side=RIGHT, fill=Y)
list_e2.config(yscrollcommand=gunlun2.set)
list_e2.place(x=1000,y=100)


lkname=StringVar()
lkname.set('显示区')
def suiji():
    global x
    x = random.choice(z_wenjian_name)
    lkname.set(x)
    global zt
    zt = Timer(0.05,suiji)
    zt.start()

label1 = Label(text='111',
             textvariable=lkname,
             font=('幼体',80,'bold'),
             width=12,height=3,bg='white')
label1.place(x=140,y=20)

xqb=StringVar()
label0=Label(text=time.strftime('%Y年%m月%d日'),font=('黑体',30,'bold'),bg='white')
label0.place(x=250,y=350)
label2=Label(text='aaa',textvariable=xqb,font=('黑体',15,'bold'),bg='white',
             width=10,height=2)
label2.place(x=550,y=350)

def xq():
    w = 0
    w = time.strftime('%w')
    if w == '1':
        xqb.set('星期一')
    elif w == '2':
        xqb.set('星期二')
    elif w == '3':
        xqb.set('星期三')
    elif w == '4':
        xqb.set('星期四')
    elif w == '5':
        xqb.set('星期五')
    elif w == '6':
        xqb.set('星期六')
    elif w == '7':
        xqb.set('星期日')
    xqs = Timer(1000,xq)
    xqs.start()







w = Entry(text,width=25,font=(20))
w.place(x=830,y=20)
w.delete(0,"end")
w.insert(0,"输入路径")

def add_w():
    try:
        global wenjian_name
        file_name = open(askopenfilename(),mode='r',encoding='utf-8')
        wenjian_name = file_name.name[file_name.name.rfind('/')+1:]
        w.delete(0,'end')
        w.insert(0,f'{wenjian_name}')
        for i in file_name:
            z_wenjian_name.append(i)
        for i in z_wenjian_name:
            list_e.insert(END,i)

    except:
        showwarning('提示信息','请选择浏览的文件')

count=1



def paichu_name():
    global x
    list_e2.insert(END,x)
    a = z_wenjian_name.index(x)
    z_wenjian_name.remove(x)
    if a == 1:
        list_e.delete(1)
    elif a==0:
        list_e.delete(0)
    else:
        list_e.delete(a)

def ks():



    global count
    count=count+1
    if count % 2 != 0:
        btn.config(text='开始(s)',foreground='Light Green')
        zt.cancel()
        paichu_name()
    elif len(z_wenjian_name)==0:
        showwarning('提示信息','请添加信息')
        return
    else:
        btn.config(text='结束(E)',foreground='Yellow')
        suiji()




btn = Button(text='开始(s)', font=('黑体', 13, 'bold'), width=8, height=3, command=ks,fg='green')
btn.place(x=100, y=400)


now_shizhong=StringVar()

def shizhong():
    sTimer = Timer(1,shizhong)
    sTimer.start()
    now =time.strftime('%H:%M:%S')
    now_shizhong.set(now)

label3=Label(text='aaaa',textvariable=now_shizhong,font=('黑体',30,'bold'),bg='white')
label3.place(x=340,y=400)

btn1 = Button(text='浏览文件',font=('黑体',10,'bold'),width= 10,height=2,fg='green',command=add_w)
btn1.place(x=1100,y=10)

def btn_1():
    text_1 = list_e.curselection()
    text_2 = list_e.get(text_1)
    list_e2.insert(END,text_2)
    z_wenjian_name.remove(text_2)
    list_e.delete(text_1)

def btn_2():
    text_1 = list_e2.curselection()#返回当前选中的索引项
    text_2 =list_e2.get(text_1)#获取内容
    list_e.insert(END,text_2)#吧内容添加到之前设置的容器list_e中
    z_wenjian_name.append(text_2)
    list_e2.delete(text_1)#删除已经排除的人员


Button(text,text='>>',font=('黑体',13),command=btn_1).place(x=965,y=150)
Button(text,text='<<',font=('黑体',13),command=btn_2).place(x=965,y=350)


label4 = Label(text,font=('黑体',13,'bold'),fg='green')
label4.config(text='备选人数:')
label4.place(x=800,y=450)

label5 = Label(text,font=('黑体',13,'bold'),fg='green')
label5.config(text='备选人数:')
label5.place(x=990,y=450)



def gaibian():
    m = list_e.size()
    label4.config(text=f'备选人数:{m}')
    a = list_e2.size()
    label5.config(text=f'备选人数:{a}')
    text.after(1000,gaibian)




xq()
gaibian()
shizhong()
text.mainloop()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值