24 多任务线程之抽奖器程序

用python编写的抽奖器
功能:
1.有12个备选选项和2个功能按钮 确定备选选项和功能按钮的位置

2.点击开始会不断旋转。选中的时候背景颜色为红色,点击停止结束
在这里插入图片描述

import threading,tkinter,time

# 创建窗口并实例化
root = tkinter.Tk()
# 窗口标题
root.title('海贼王')
# 窗口尺寸
root.minsize(300,300)

# 12个按钮的基本参数设置和摆放位置
btn1 = tkinter.Button(root,text = '路飞',bg = 'red')
btn1.place(x=20,y=20,width=50,height=50)

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

btn3 = tkinter.Button(root,text = '香吉士',bg = 'white')
btn3.place(x=160,y=20,width=50,height=50)

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

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

btn6 = tkinter.Button(root,text = '费兰吉',bg = 'white')
btn6.place(x=230,y=160,width=50,height=50)

btn7 = tkinter.Button(root,text = '乔巴',bg = 'white')
btn7.place(x=230,y=230,width=50,height=50)

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

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

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

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

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

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

stop_sign = False

def round():
    i = 1

    while True:
        time.sleep(0.2)
        for x in all_list:
            x['bg'] = 'white'
        all_list[i]['bg'] = 'red'
        i += 1
        if i >= len(all_list):
            i = 0
        if stop_sign == True:
            break


def sta():
    global stop_sign
    stop_sign = False
    #round()
    t = threading.Thread(target = round)
    t.start()

def stop():
    global stop_sign
    stop_sign = True

# 开始按钮
btn_start = tkinter.Button(root,text='开始',command=sta)
btn_start.place(x=90,y=125,width=50,height=50)

# 结束按钮
btn_stop = tkinter.Button(root,text='停止',command=stop)
btn_stop.place(x=160,y=125,width=50,height=50)

# 显示窗口
root.mainloop()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值