赞
踩
效果展示:
具体需求:
1.点击开始按钮后,轮盘开始转动;点击结束后,弹窗弹出对应奖品
2.轮盘开始转动后,在每个奖品停留0.2秒
2.菜单项中有作者和退出选项;选择作者选项,弹窗弹出作者姓名,点击退出程序后退出程序
源码:
- import tkinter as tk
- import time
- import threading
- import tkinter.messagebox as tkbox
-
- win = tk.Tk()
- win.title("幸运抽奖")
- win.geometry("400x400")
- bg = "white"
- sleep = True
- vary_sleep = True
- text1 = tk.Label(win,text="奖品1:\n卡通水杯",bg=bg,height=3,width=8)
- text1.place(x=30,y=20)
- text2 = tk.Label(win,text="奖品2:\n体重秤",bg=bg,height=3,width=8)
- text2.place(x=115,y=20)
- text3 = tk.Label(win,text="奖品3:\n旺仔QQ糖",bg=bg,height=3,width=8)
- text3.place(x=200,y=20)
- text4 = tk.Label(win,text="奖品4:\n秘制小汉堡",bg=bg,height=3,width=8)
- text4.place(x=285,y=20)
- text5 = tk.Label(win,text="奖品5:\n好果汁吃",bg=bg,height=3,width=8)
- text5.place(x=285,y=85)
- text6 = tk.Label(win,text="奖品6:\n王甜心饺子",bg=bg,height=3,width=8)
- text6.place(x=285,y=150)
- text7 = tk.Label(win,text="奖品7:\n暑假密卷",bg=bg,height=3,width=8)
- text7.place(x=285,y=215)
- text8 = tk.Label(win,text="奖品8:\n旺仔套装",bg=bg,height=3,width=8)
- text8.place(x=285,y=280)
- text9 = tk.Label(win,text="奖品9:\n大逼斗",bg=bg,height=3,width=8)
- text9.place(x=200,y=280)
- text10 = tk.Label(win,text="奖品10:\n战斧牛排",bg=bg,height=3,width=8)
- text10.place(x=115,y=280)
- text11 = tk.Label(win,text="奖品11:\n放假",bg=bg,height=3,width=8)
- text11.place(x=30,y=285)
- text12 = tk.Label(win,text="奖品12:\n搬家去云南",bg=bg,height=3,width=8)
- text12.place(x=30,y=215)
- text13 = tk.Label(win,text="奖品13:\n高考加分",bg=bg,height=3,width=8)
- text13.place(x=30,y=150)
- text14 = tk.Label(win,text="奖品14:\n海贼王",bg=bg,height=3,width=8)
- text14.place(x=30,y=85)
- text_list = [text1,text2,text3,text4,text5,text6,text7,text8,text9,text10,text11,text12,text13,text14]
-
- def menu():
- tkbox.showinfo("作者", "李狗蛋")
-
- mainmenu = tk.Menu(win)
- filemenu = tk.Menu(mainmenu,tearoff=False)
- mainmenu.add_cascade (label="操作",menu=filemenu)
- filemenu.add_command (label="作者",command=menu)
- filemenu.add_command (label="退出",command=win.quit)
-
- win.config (menu=mainmenu)
-
- def end_code():
- global vary_sleep
- vary_sleep = False
-
- def rounds():
- global sleep,vary_sleep
- if sleep==True:
- x = 0
- while True:
- if vary_sleep==False:
- value = text_list[x-1]['text']
- tkbox.showinfo("感谢您的关注","恭喜获得:{}".format(value))
- tkbox.showinfo("如果对您有帮助", "请前往某某地 领取您的奖品!!!")
- return
- else:
- time.sleep(0.2)
- for i in text_list:
- i['bg'] = "white"
- text_list[x]['bg'] = 'red'
- x += 1
- if x >= len(text_list):
- x = 0
- else:
- return
-
- def start():
- t = threading.Thread(target=rounds)
- t.start()
-
- start_button = tk.Button(win,text="开始",height=4,width=10,command=start)
- start_button.place(x=105,y=125)
- start_button = tk.Button(win,text="结束",height=4,width=10,command=end_code)
- start_button.place(x=195,y=125)
- win.mainloop()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。