• tkinter--抽奖


    import random
    from tkinter import *
    import threading
    import time
    import tkinter as tk
    flag =False
    #初始化窗口
    root = Tk()
    photo = tk.PhotoImage(file="3.png")
    theLabel = tk.Label(root,
            # text = "我是内容,
    请你阅读",
    # 内容
            justify = tk.LEFT,
    # 对齐方式
            image = photo,
    # 加入图片
            compound = tk.CENTER,
    # 关键:设置为背景图片
            font = ("华文行楷", 20),
    # 字体和字号
            fg = "white")  # 前景色
    theLabel.pack()
    root.title('年会抽奖活动')
    root.geometry('800x500+300+150')
    root.configure(bg='blue')
    #标签
    # var1 = StringVar(value='即 将 开 始')
    first = Label(root,text='',font=('宋体',20))
    first.place(x=180,y=100,width=400,height=100)
    second = Label(root,text='',font=('宋体',20))
    second.place(x=180,y=210,width=400,height=100)
    third = Label(root,text='',font=('宋体',20))
    third.place(x=180,y=320,width=400,height=100)
    lis =[]
    def switch_1():
        global lis
        global flag
        if flag ==False:
            with open('名单',mode='r',encoding='utf-8') as f:
                for i in f:
                    i = i.strip()
                    lis.append(i)
            first_price = random.choice(lis)
            first['text'] ='一等奖:'+first_price
            lis.remove(first_price)
            print(lis)
            flag = True
        else:
            first_price = random.choice(lis)
            first['text'] = '一等奖:' + first_price
            lis.remove(first_price)
            print(lis)
    def butStartClict_1():
        t = threading.Thread(target=switch_1)
        t.start()
    def switch_2():
        global lis
        global flag
        if flag == False:
            with open('名单', mode='r', encoding='utf-8') as f:
                for i in f:
                    i = i.strip()
                    lis.append(i)
            second_price_1 = random.sample(lis, 2)
            a = second_price_1[0]
            b = second_price_1[1]
            second['text'] = '二等奖人员:'+ a
            third['text'] ='er等奖人员:'+b
            lis.remove(a)
            lis.remove(b)
            print(lis)
            flag = True
        else:
            second_price_1 = random.sample(lis, 2)
            a = second_price_1[0]
            b = second_price_1[1]
            second['text'] = '二等奖人员:' + a
            third['text'] = '二等奖人员:' + b
            lis.remove(a)
            lis.remove(b)
            print(lis)
    
    def butStartClict_2():
        t = threading.Thread(target=switch_2)
        t.start()
    btnStart_1 = Button(root,text='一等奖开始',bg='green',command=butStartClict_1)
    btnStart_1.place(x=30,y=30,width=80,height=50)
    btnStart_2 = Button(root,text='二等奖开始',bg='green',command=butStartClict_2)
    btnStart_2.place(x=290,y=30,width=80,height=50)
    
    #结束按钮
    def btnStopClick():
        first['text'] =''
        second['text'] = ''
        third['text'] = ''
    btnStop_1 = Button(root,text='一等奖结束',bg='green',command=btnStopClick)
    btnStop_1.place(x=160,y=30,width=80,height=50)
    btnStop_2 = Button(root,text='二等奖结束',bg='green',command=btnStopClick)
    btnStop_2.place(x=420,y=30,width=80,height=50)
    root.mainloop()
  • 相关阅读:
    [导入]起点
    docker 07 多容器应用程序
    Docker WARNING: Ignoring https://dlcdn.alpinelinux.org/alpine/v3.15/main: temporary error (try again later)
    Docker 06 持久化到主机本地系统。也就是常说的挂载
    小程序开发,不支持打开非业务域名,请重新配置。
    Docker 01 安装DockerEngine和Docker Cli
    Docker 02 Docker基本概念
    Docker 04 构建并运行基础镜像
    win10使用scp命令通过密钥rsa进行传输的bad Permissions的解决方案:WARNING: UNPROTECTED PRIVATE KEY FILE!
    Docker 05 构建镜像发送到中央仓库
  • 原文地址:https://www.cnblogs.com/jdwy24/p/13958793.html
Copyright © 2020-2023  润新知