python写抽奖转盘_python实现转盘效果 python实现轮盘抽奖游戏
本文实例为大家分享了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
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实现转盘效果 python实现轮盘抽奖游戏相关推荐
- python基础编程练习_python基础练习之几个简单的游戏
文档介绍 利用python写"猜数字","猜词语","谁是卧底"这三个游戏,从而快速掌握python编程的入门知识,包括python语法/列 ...
- python写窗体程序_python写窗口
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 最近在学习 pyqt5 gui 编程,大致路线是找了套网课<撩课-pyth ...
- python写推箱子_python写的推箱子小游戏
原标题:python写的推箱子小游戏 导语 Python 功能强大,可以写爬虫.服务器.数据分析.AI--当然,也可以写游戏. 用python写了个推箱子小游戏,在这里分享给大家,让我们愉快地开始吧~ ...
- python写了代码_Python写代码的用法建议
1.Mutable and immutable types Python有两种内置或用户定义的类型 可变类型是允许就地修改内容的类型.典型的可变列表是列表和词典:所有列表都有变异方法,如 list.a ...
- python 写txt 换行_python中写入txt文件需要换行,以及\r 和\n
在Python中,用open()函数打开一个txt文件,写入一行数据之后需要一个换行 如果直接用 f.write('\n') 只会在后面打印一个字符串'\n',而不是换行' 需要用 f.write(' ...
- python 写一个计算器_Python | 写个计算器吧
今天咱们用python来写一个计算器,计算一组数的最大公约数和最小公倍数吧. 注:本文使用python3 01 死循环 下面给出一段看似正确的代码,这段代码的作用是给出n1,n2的最小公倍数. 你可以 ...
- 用python写一个函数_Python基础-函数篇
1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 函数与函数式编程 1.面向对象: 华山派----> ...
- 用python写一个通讯录_python写一个通讯录
闲着没事,用python写一个模拟通讯录,要求要实现常用的通讯录的功能,基本流程如下 接下来就按照这个流程实现各个模块的功能 1. 定义一个类,并初始化 def __init__(self): w ...
- python写xml文件_python写入xml文件的方法
Python 这篇文章主要介绍了Python 2.7.x 和 3.x 版本的重要区别小结,需要的朋友可以参考下 ... 脚本之家1322020-05-16 Python 今天小编就为大家分享一篇Pyt ...
最新文章
- 寻找兄弟单词(2012.5.6百度实习)
- AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas
- Flume-ng 高可用搭建-与测试
- html button跳转页面_HTML跳转到页面指定位置的几种方法
- GC算法-增量式垃圾回收
- urlib2和requests模拟登陆查询MD5
- 11. 旋转数组的最小数字
- 云原生和ServiceMesh主要组件--理解K8s/Istio/Envoy
- jquery1.9 下检测浏览器类型和版本的方法
- informix多张表UPDATE时不能用别名
- 晚上没有路灯,我骑的很慢
- 菜鸟也要懂点设计模式|用Python设计一个请假模式
- hdu 3925 一道复杂的简单题
- Hyper-V复制配置前评估
- 【Android_CN_OAID】安卓设备唯一标识解决方案,可作为移动安全联盟统一 SDK (miit_mdid_xxx.aar)的替代方案。
- java redis锁_Java中Redis锁的实现
- Echarts清空图表:There is a chart instance already initialized on the dom.
- php中单引号双引号那点事---顺便说说把php变量的值传给js
- 校园版网络教学平台搭建方案(学生端)
- 微软人工智能-深度学习框架和工具.md