zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    网站安全策略
    防止表单重复提交的几种策略
    Laravel5中防止XSS跨站攻击的方法
    PHP + ORACLE 远程连接数据库环境配置
    iview table表格内容为数组或者对象的子元素时问题讨论
    jquery中 $(xxx).each() 和 $.each()的区别,以及enter键一键登录
    vue.js 强行赋值、刷新数组或者对象 方法之 $.set()
    vue 组件,以及组件的复用
    vue 和 jquery混合使用
    JS清除空格之trim()方法
  • 原文地址:https://www.cnblogs.com/jdwy24/p/13958793.html
Copyright © 2011-2022 走看看