python实现转盘效果 python实现轮盘抽奖游戏


Posted in Python onJanuary 22, 2019

本文实例为大家分享了python实现转盘效果的具体代码,供大家参考,具体内容如下

#抽奖 面向对象版本
import tkinter
import time
import threading
 
class choujiang:
  #初始化魔术方法
  def __init__(self):
    #准备好界面
    self.root = tkinter.Tk()
    self.root.title('lowB版转盘')
    self.root.minsize(300, 300)
    # 声明一个是否按下开始的变量
    self.isloop = False
    self.newloop = False
    #调用设置界面的方法
    self.setwindow()
    self.root.mainloop()
 
 
 
  #界面布局方法
  def setwindow(self):
    #开始停止按钮
    self.btn_start = tkinter.Button(self.root, text = 'start/stop',command = self.newtask)
    self.btn_start.place(x=90, y=125, width=50, height=50)
 
    self.btn1 = tkinter.Button(self.root, text='赵', bg='red')
    self.btn1.place(x=20, y=20, width=50, height=50)
 
    self.btn2 = tkinter.Button(self.root, text='钱', bg='white')
    self.btn2.place(x=90, y=20, width=50, height=50)
 
    self.btn3 = tkinter.Button(self.root, text='孙', bg='white')
    self.btn3.place(x=160, y=20, width=50, height=50)
 
    self.btn4 = tkinter.Button(self.root, text='李', bg='white')
    self.btn4.place(x=230, y=20, width=50, height=50)
 
    self.btn5 = tkinter.Button(self.root, text='周', bg='white')
    self.btn5.place(x=230, y=90, width=50, height=50)
 
    self.btn6 = tkinter.Button(self.root, text='吴', bg='white')
    self.btn6.place(x=230, y=160, width=50, height=50)
 
    self.btn7 = tkinter.Button(self.root, text='郑', bg='white')
    self.btn7.place(x=230, y=230, width=50, height=50)
 
    self.btn8 = tkinter.Button(self.root, text='王', bg='white')
    self.btn8.place(x=160, y=230, width=50, height=50)
 
    self.btn9 = tkinter.Button(self.root, text='冯', bg='white')
    self.btn9.place(x=90, y=230, width=50, height=50)
 
    self.btn10 = tkinter.Button(self.root, text='陈', bg='white')
    self.btn10.place(x=20, y=230, width=50, height=50)
 
    self.btn11 = tkinter.Button(self.root, text='褚', bg='white')
    self.btn11.place(x=20, y=160, width=50, height=50)
 
    self.btn12 = tkinter.Button(self.root, text='卫', bg='white')
    self.btn12.place(x=20, y=90, width=50, height=50)
 
    # 将所有选项组成列表
    self.girlfrends = [self.btn1,self.btn2,self.btn3,self.btn4,self.btn5,self.btn6,self.btn7,self.btn8,self.btn9,self.btn10,self.btn11,self.btn12]
 
  def rounds(self):
    # 判断是否开始循环
    if self.isloop == True:
      return
 
    # 初始化计数 变量
    i = 0
    # 死循环
    while True:
      if self.newloop == True:
        self.newloop = False
        return
 
      # 延时操作
      time.sleep(0.1)
      # 将所有的组件背景变为白色
      for x in self.girlfrends:
        x['bg'] = 'white'
 
      # 将当前数值对应的组件变色
      self.girlfrends[i]['bg'] = 'red'
      # 变量+1
      i += 1
      # 如果i大于最大索引直接归零
      if i >= len(self.girlfrends):
        i = 0
 
  # 建立一个新线程的函数
  def newtask(self):
    if self.isloop == False:
      # 建立线程
      t = threading.Thread(target = self.rounds)
      # 开启线程运行
      t.start()
      # 设置循环开始标志
      self.isloop = True
    elif self.isloop == True:
      self.isloop = False
      self.newloop = True
 
 
c = choujiang()

小编再为大家分享一款python模拟轮盘抽奖的游戏

python3.x的版本测试中文的变量名

from random import random
#轮盘赌lpd,奖项分布jxfb,本次转盘读数bclpds,中奖情况zjqk,本次战况bczk,
def lpd(jxfb):
  bclpds = random()
  for k, v in jxfb.items():
    if v[0]<=bclpds<v[1]:
      return k

jxfb = {'一等奖':(0, 0.08),
          '二等奖':(0.08, 0.3),
          '三等奖':(0.3, 1.0)}

zjqk = dict()
#模拟玩10000次,统计中奖情况
for i in range(10000):
  bczk = lpd(jxfb)
  zjqk[bczk] = zjqk.get(bczk, 0) + 1

for item in zjqk.items():
  print(item)

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

Python 相关文章推荐
使用Python的urllib2模块处理url和图片的技巧两则
Feb 18 Python
利用python批量检查网站的可用性
Sep 09 Python
Python检测生僻字的实现方法
Oct 23 Python
python 列表降维的实例讲解
Jun 28 Python
python判断数字是否是超级素数幂
Sep 27 Python
Python深拷贝与浅拷贝用法实例分析
May 05 Python
Python获取数据库数据并保存在excel表格中的方法
Jun 12 Python
flask框架自定义过滤器示例【markdown文件读取和展示功能】
Nov 08 Python
python+selenium+Chrome options参数的使用
Mar 18 Python
OpenCV利用python来实现图像的直方图均衡化
Oct 21 Python
python 自定义异常和主动抛出异常(raise)的操作
Dec 11 Python
Python面向对象之成员相关知识总结
Jun 24 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
Python多线程原理与用法实例剖析
Jan 22 #Python
python解析含有重复key的json方法
Jan 22 #Python
You might like
PHP 远程关机实现代码
2009/11/10 PHP
LotusPhp笔记之:基于ObjectUtil组件的使用分析
2013/05/06 PHP
php实现读取超大文件的方法
2014/07/28 PHP
Laravel 5框架学习之日期,Mutator 和 Scope
2015/04/08 PHP
如何解决PHP使用mysql_query查询超大结果集超内存问题
2016/03/14 PHP
PHP程序员的技术成长规划
2016/03/25 PHP
PHP利用超级全局变量$_POST来接收表单数据的实例
2016/11/05 PHP
jquery对单选框,多选框,文本框等常见操作小结
2014/01/08 Javascript
在JavaScript中构建ArrayList示例代码
2014/09/17 Javascript
javascript显示中文日期的方法
2015/06/18 Javascript
移动Web中图片自适应的两种JavaScript解决方法
2015/06/18 Javascript
深入理解JavaScript中的箭头函数
2015/07/28 Javascript
js实现跨域的几种方法汇总(图片ping、JSONP和CORS)
2015/10/25 Javascript
非常实用的js验证框架实现源码 附原理方法
2016/06/08 Javascript
JavaScript中 this 指向问题深度解析
2017/02/21 Javascript
nodejs Assert中equal(),strictEqual(),deepEqual(),strictDeepEqual()比较
2017/09/18 NodeJs
超详细的5个Shell脚本实例分享(值得收藏)
2019/08/15 Javascript
JS实现躲避粒子小游戏
2020/06/18 Javascript
Python中使用logging模块代替print(logging简明指南)
2014/07/09 Python
利用Python和OpenCV库将URL转换为OpenCV格式的方法
2015/03/27 Python
pycharm运行出现ImportError:No module named的解决方法
2018/10/13 Python
浅谈django的render函数的参数问题
2018/10/16 Python
Django之PopUp的具体实现方法
2019/08/31 Python
Python求平面内点到直线距离的实现
2020/01/19 Python
基于Python的自媒体小助手---登录页面的实现代码
2020/06/29 Python
anaconda3安装及jupyter环境配置全教程
2020/08/24 Python
python中yield的用法详解
2021/01/13 Python
eBay比利时购物网站:eBay.be
2019/08/09 全球购物
英国家居装饰品、户外家具和玻璃器皿购物网站:Rinkit.com
2019/11/04 全球购物
安德玛菲律宾官网:Under Armour菲律宾
2020/07/28 全球购物
交通安全标语
2014/06/06 职场文书
雷峰塔导游词
2015/02/09 职场文书
部门经理助理岗位职责
2015/04/13 职场文书
小学生作文写作技巧100例,非常实用!
2019/07/08 职场文书
mysql查询的控制语句图文详解
2021/04/11 MySQL
python 中的@运算符使用
2021/05/26 Python