Python实现轮盘抽奖小程序(带界面)

效果展示:

 具体需求:

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()

  • 0
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值