2022-02-07开工大吉的抽奖程序

思路

15个红包,每个人喊开始和停,随机生成红包的序号
红包的领完后,对应的号码需要在奖池中删除

代码

import tkinter
import random
import threading
import time

# 初始化窗口
root = tkinter.Tk()
root.title('开始停抽奖程序')
root.geometry('500x500+400+200')
root.resizable(False, False)
root.flag = True
# 中奖Lable标签

numLable = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
numLable['fg'] = 'red'
numLable.place(x=180, y=200, width=150, height=100)

hongbaoshuliang = ['1', '2', '3', '4', '5', '6','7','8','9','10','11','12','13','14','15']

def switch():
    root.flag = True
    while root.flag:
        i = random.randint(0, len(hongbaoshuliang) - 1)
        numLable['text'] = hongbaoshuliang[i]
        time.sleep(0.1)
    hongbaoshuliang.pop(i)
# 开始按钮
def butStartClick():
    t = threading.Thread(target=switch)
    t.start()
btnStart = tkinter.Button(root, text='开始', command=butStartClick)
btnStart.place(x=30, y=30, width=80, height=20)

# 结束按钮
def btnStopClick():
    root.flag = False

butStop = tkinter.Button(root, text='停止', command=btnStopClick)
butStop.place(x=160, y=30, width=80, height=20)

# 启动主程序
root.mainloop()
image.png

优化思路

明年争取做个声控的

你可能感兴趣的:(2022-02-07开工大吉的抽奖程序)