前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python 实现可视化抽奖

Python 实现可视化抽奖

作者头像
Yuyy
发布2022-06-28 19:19:29
6930
发布2022-06-28 19:19:29
举报
文章被收录于专栏:yuyy.info技术专栏

本文最后更新于 1163 天前,其中的信息可能已经有所发展或是发生改变。

代码

代码语言:javascript
复制
from tkinter import *
import threading
import time
root = Tk()
root.title('大转盘')
root.minsize(300,300)

btn1=Button(root,text='樱桃',bg='red')
btn1.place(x=20,y=20,width=50,height=50)

btn2 = Button(root, text='香蕉', bg='white')
btn2.place(x=90, y=20, width=50, height=50)

btn3 = Button(root, text='苹果', bg='white')
btn3.place(x=160, y=20, width=50, height=50)

btn4 = Button(root, text='西瓜', bg='white')
btn4.place(x=230, y=20, width=50, height=50)

btn5 = Button(root, text='鸭梨', bg='white')
btn5.place(x=230, y=90, width=50, height=50)

btn6 = Button(root, text='榴莲', bg='white')
btn6.place(x=230, y=160, width=50, height=50)

btn7 = Button(root, text='柚子', bg='white')
btn7.place(x=230, y=230, width=50, height=50)

btn8 =Button(root, text='葡萄', bg='white')
btn8.place(x=160, y=230, width=50, height=50)

btn9 = Button(root, text='草莓', bg='white')
btn9.place(x=90, y=230, width=50, height=50)

btn10 = Button(root, text='芒果', bg='white')
btn10.place(x=20, y=230, width=50, height=50)

btn11 = Button(root, text='荔枝', bg='white')
btn11.place(x=20, y=160, width=50, height=50)

btn12 = Button(root, text='甘蔗', bg='white')
btn12.place(x=20, y=90, width=50, height=50)

fruitlist=[btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12,]


i=0
stopid=0
flag=False
def round():
    global i
    global flag
    global stopid
    print('进入round')
    for item in fruitlist:
        item['bg']='white'
    while True:
        fruitlist[i]['bg']='red'
        time.sleep(0.2)
        fruitlist[i]['bg']='white'
        print(i)
        if i>=11:
            i=0
        else:
            i+=1
        if not flag:
            stopid=i
            fruitlist[i]['bg']='red'
            break

def action():
    global flag
    global i
    print('进入action')
    if not flag:
        flag=True
        i=stopid
        t=threading.Thread(target=round)
        t.start()

def stop():
    print('进入stop')
    global flag
    flag=False

btn_start=Button(root,text='开始',command=lambda : action())
btn_start.place(x=90,y=125,width=50,height=50)
btn_stop=Button(root,text='暂停',command=lambda : stop())
btn_stop.place(x=160,y=125,width=50,height=50)

root.mainloop()

运行结果

Post Views: 435

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-4-22 9,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 代码
  • 运行结果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档