本文实例为大家分享了python实现大转盘抽奖的具体代码,供大家参考,具体内容如下
选择转盘中的某一个方框,来进行抽奖
import tkinter #导入线程模块 import threading import time #导入代码的sleep 代码休眠 root = tkinter.Tk() root.title('大转盘') root.minsize(300,300) #摆放按钮 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) #将所有选项组成列表 fruitlists = [btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12] #是否开启循环的标志 isloop = False #是否停止标志 stopsign=False #是否接收到 stop信号 #存储停止id------用于进行stop后的重新启动 stopid=None def round(): global isloop global stopid #判断是否开始循环 if isloop == True: return i=1 if isinstance(stopid,int): i=stopid while True: #延时操作 time.sleep(0.2) #将所有的组件背景变为白色 for x in fruitlists: x['bg'] = 'white' #将当前数值对应的组件变色 fruitlists[i]['bg'] = 'red' #变量+1 i += 1 print('当前i为',i) #当前i,用来追踪当前位置 #如果i大于最大索引直接归零 if i >= len(fruitlists): i = 0 if stopsign == True:#当停止标志 为真时 isloop=False stopid =i#赋值stopid break def stop1(): global stopsign if stopsign ==True:#当多接收stop1()函数时 ,直接跳过 return stopsign=True #建立一个新线程的函数 def newtask(): global isloop global stopsign #建立线程 stopsign=False #print(stopsign) #打印 点击开始时的stopsign t = threading.Thread(target = round) #开启线程运行 t.start() # 设置循环开始标志 isloop = True #开始按钮 btn_start = tkinter.Button(root,text = 'start',command = newtask) btn_start.place(x = 90,y = 125,width = 50,height = 50) #停止按钮 btn_stop = tkinter.Button(root,text = 'stop',command=stop1) btn_stop.place(x = 160,y = 125,width = 50,height = 50) root.mainloop()
效果图:
就是上图这个界面了:
start 开始按钮
stop 结束按钮
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2024年09月22日
2024年09月22日
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 大自然音乐系列《鲸声奇遇》[WAV/CUE/分轨][566.8MB]
- 陆虎.2024-时间是个有趣的东西【天娱传媒】【FLAC分轨】
- 江淑娜.1988-琼瑶原著电视连续剧主题曲【风格】【WAV+CUE】