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实现转盘效果的具体代码,供大家参考,具体内容如下 #抽奖 面向对象版本 import tkinter import time import threading clas ...
- python写抽奖转盘_python实现转盘效果 python实现轮盘抽奖游戏
本文实例为大家分享了python实现转盘效果的具体代码,供大家参考,具体内容如下 #抽奖 面向对象版本 import tkinter import time import threading clas ...
- python转盘抽奖_python实现转盘效果 python实现轮盘抽奖游戏
本文实例为大家分享了python实现转盘效果的具体代码,供大家参考,具体内容如下 #抽奖 面向对象版本 import tkinter import time import threading clas ...
- python编程命令大全_Python命令简介,python命令使用大全
python命令使用大全,Python被称为高级解释性和面向对象的编程语言.它是由GuidovanRossum开发的.Python易于学习,易于使用和维护,可移植,可扩展的可扩展GUI编程.Pytho ...
- 抽奖滚动效果 python_python实现转盘效果 python实现轮盘抽奖游戏
python实现转盘效果 python实现轮盘抽奖游戏 来源:中文源码网 浏览: 次 日期:2019年11月5日 [下载文档: python实现转盘效果 python实现轮盘抽奖游戏.t ...
- python画画代码大全_python 相关主题_Debug5
Python主题 Python 2020年11月16日 14:3020 如何使用python random模块生成随机值,随机打乱顺序 Python 2020年11月16日 11:3030 pytho ...
- python基础编程练习_python基础练习之几个简单的游戏
文档介绍 利用python写"猜数字","猜词语","谁是卧底"这三个游戏,从而快速掌握python编程的入门知识,包括python语法/列 ...
- python爬虫教程大全_python爬虫入门教程
爬虫是一个是一个好玩的技术,偷偷爬取mm的照片,爬取知乎用户头像等等,这些教程经验帖在网上随便一搜,到处都是:那么今天小编将给大家简单讲讲python爬虫的入门.鉴于经验排版模式有限,所以这里只能简单 ...
- python学习内容大全_Python学习资料收集
Python 实用资料收集 一 . Python 常用链接和基本工具 1. Online Python Tutor :首先,隆重推荐这个牛逼的网站,这是我看到的最让人爱不 释手的学习 Python 的 ...
最新文章
- delphi 插入表格HTML代码
- [BZOJ4556][TJOI2016HEOI2016]字符串(二分答案+后缀数组+RMQ+主席树)
- 【Leetcode | easy】有效的括号
- SharePoint 2013 自定义扩展菜单(二)
- Redis :01---Redis简介和安装
- 赋能尖端科技 推进智能布局 |《HPC高性能计算数据存储解决方案蓝皮书》正式发布
- python批量下载百度照片
- linux脚本中swith,BeanShell中switch语句
- PHP框架Yii系列教程(四):使用Memcache保存会话
- sql时间小问题汇总
- 如何用C#对Gridview的项目进行汇总统计?
- openwrt 需要高级浏览器_斐讯K2P刷openwrt设置mentohust
- 电脑蓝牙耳机,蓝牙耳机能连笔记本吗_笔记本电脑怎么接蓝牙耳机吗-win7之家
- 斐波那契数列几个公式
- 投影仪家用哪个牌子好?如何选择投影仪
- EChart 展现内蒙古地图数据
- Android HIDL HAL 接口定义语言详解
- Q for Mortals2笔记 -- 列表
- 200条公务员常识!
- 数据结构实践项目:校园路线导航图