python实现大转盘抽奖效果


Posted in Python onJanuary 22, 2019

本文实例为大家分享了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()

效果图:

python实现大转盘抽奖效果

就是上图这个界面了:

start 开始按钮

stop 结束按钮

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python读写Excel文件的实例
Nov 01 Python
python logging日志模块的详解
Oct 29 Python
Python使用pickle模块实现序列化功能示例
Jul 13 Python
Python拼接字符串的7种方法总结
Nov 01 Python
对python csv模块配置分隔符和引用符详解
Dec 12 Python
Python 内置变量和函数的查看及说明介绍
Dec 25 Python
Python实现计算长方形面积(带参数函数demo)
Jan 18 Python
Python实现UDP程序通信过程图解
May 15 Python
在keras里面实现计算f1-score的代码
Jun 15 Python
python+selenium 简易地疫情信息自动打卡签到功能的实现代码
Aug 22 Python
Python通过format函数格式化显示值
Oct 17 Python
Python线程池与GIL全局锁实现抽奖小案例
Apr 13 Python
Python函数返回不定数量的值方法
Jan 22 #Python
python实现转盘效果 python实现轮盘抽奖游戏
Jan 22 #Python
Python Pillow Image Invert
Jan 22 #Python
python 通过类中一个方法获取另一个方法变量的实例
Jan 22 #Python
对Python 获取类的成员变量及临时变量的方法详解
Jan 22 #Python
Python实现深度遍历和广度遍历的方法
Jan 22 #Python
Python遍历文件夹 处理json文件的方法
Jan 22 #Python
You might like
一条久听不愿放下的DIY森海MX500,三言两语话神奇
2021/03/02 无线电
php split汉字
2009/06/05 PHP
php数组去重复数据示例
2014/02/25 PHP
PHP消息队列用法实例分析
2016/02/12 PHP
微信第三方登录(原生)demo【必看篇】
2017/05/26 PHP
详细解读php的命名空间(二)
2018/02/21 PHP
javascript 设为首页与加入收藏兼容多浏览器代码
2011/01/11 Javascript
jquery表单插件form使用方法详解
2017/01/20 Javascript
微信小程序实现添加手机联系人功能示例
2017/11/30 Javascript
Node层模拟实现multipart表单的文件上传示例
2018/01/02 Javascript
Vue中的slot使用插槽分发内容的方法
2018/03/01 Javascript
详解iframe跨域的几种常用方法(小结)
2019/04/29 Javascript
vue + el-form 实现的多层循环表单验证
2020/11/25 Vue.js
[53:50]CHAOS vs Mineski 2019国际邀请赛小组赛 BO2 第一场 8.16
2019/08/18 DOTA
[47:43]完美世界DOTA2联赛PWL S3 Magama vs GXR 第二场 12.19
2020/12/24 DOTA
用Python输出一个杨辉三角的例子
2014/06/13 Python
剖析Django中模版标签的解析与参数传递
2015/07/21 Python
Python实现学校管理系统
2018/01/11 Python
解决pycharm 误删掉项目文件的处理方法
2018/10/22 Python
python使用PIL模块获取图片像素点的方法
2019/01/08 Python
Django框架模板的使用方法示例
2019/05/25 Python
python实现两个dict合并与计算操作示例
2019/07/01 Python
简单了解python代码优化小技巧
2019/07/08 Python
基于python实现FTP文件上传与下载操作(ftp&sftp协议)
2020/04/01 Python
浅谈Python程序的错误:变量未定义
2020/06/02 Python
印度最大的酒店品牌网络:OYO Rooms
2016/07/24 全球购物
全球游戏Keys和卡片市场:GamesDeal
2018/03/28 全球购物
历史学专业毕业生求职信
2013/09/27 职场文书
高三自我鉴定范文
2013/10/19 职场文书
《小松树和大松树》教学反思
2014/02/20 职场文书
教育英语专业毕业生的求职信
2014/03/13 职场文书
四议两公开实施方案
2014/03/28 职场文书
广告设计专业毕业生自我鉴定
2014/09/27 职场文书
Python django中如何使用restful框架
2021/06/23 Python
【海涛教你打DOTA】剑圣第一人称视角解说
2022/04/01 DOTA
SpringBoot详解执行过程
2022/07/15 Java/Android