黑松山资源网 Design By www.paidiu.com
本文实例为大家分享了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)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月07日
2024年10月07日
- 群星.1991-音乐工厂1·皇后大道东【音乐工厂】【WAV+CUE】
- 群星.1992-音乐工厂2·首都【音乐工厂】【WAV+CUE】
- 群星.1994-音乐工厂3·儿童乐园【音乐工厂】【WAV+CUE】
- 胡鸿钧.2021-ex:CHANGE【星梦娱乐】【WAV+CUE】
- 班得瑞原装进口《第一张新世纪专辑:仙境》1CD[APE/CUE分轨][292.3MB]
- 伍佰《摇滚教父 伍佰黄金精选 2CD》[WAV+CUE][990MB]
- 班得瑞原装进口《第二张新世纪专辑:寂静山林》1CD[APE/CUE分轨][327.1MB]
- Beyond.1989-真的见证(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 陈怡婷.2024-予你的心谁来赔【福茂】【FLAC分轨】
- 陈冠希.2003-HITS.OR.MISSES【英皇娱乐】【WAV+CUE】
- 班得瑞原装进口《第三张新世纪专辑:春野》1CD[APE/CUE分轨][278.9MB]
- 班得瑞原装进口《第四张新世纪专辑:蓝色天际》1CD[APE/CUE分轨][284.8MB]
- 班得瑞原装进口《第五张新世纪专辑:迷雾森林+EP》1CD[APE/CUE分轨][334.2MB]
- 田震.1997-顺其自然(日版)【红星生产社】【WAV+CUE】
- 小虫.1996-想得太美【滚石】【WAV+CUE】