思路
15個(gè)紅包揉稚,每個(gè)人喊開始和停荞彼,隨機(jī)生成紅包的序號
紅包的領(lǐng)完后秕衙,對應(yīng)的號碼需要在獎(jiǎng)池中刪除
代碼
import tkinter
import random
import threading
import time
# 初始化窗口
root = tkinter.Tk()
root.title('開始停抽獎(jiǎng)程序')
root.geometry('500x500+400+200')
root.resizable(False, False)
root.flag = True
# 中獎(jiǎng)Lable標(biāo)簽
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)
# 結(jié)束按鈕
def btnStopClick():
root.flag = False
butStop = tkinter.Button(root, text='停止', command=btnStopClick)
butStop.place(x=160, y=30, width=80, height=20)
# 啟動(dòng)主程序
root.mainloop()
優(yōu)化思路
明年?duì)幦∽鰝€(gè)聲控的