python编写实现抽奖器


Posted in Python onSeptember 10, 2020

本文实例为大家分享了python编写实现抽奖器的具体代码,供大家参考,具体内容如下

# coding=utf-8
import sys
import os
import openpyxl
if sys.version_info[0] == 2:
 import Tkinter
 from Tkinter import *
else:
 import tkinter as Tkinter
 from tkinter import *
from tkinter import messagebox

import random
data = []
going = True
is_run = False

def getNameList():
 path=os.getcwd()
 wb=openpyxl.load_workbook(r'list.xlsx')
 sheet=wb["Sheet1"]
 macList = []
 for i in range(2,sheet.max_row+1):
  macList.append(sheet.cell(row=i,column=1).value)
 return macList

def lottery_roll(var1, var2):
 global going
 if going:
 show_member = random.choice(data)
 var1.set(show_member)
 window.after(50, lottery_roll, var1, var2)
 else:
 var2.set('还有{}个小幸运鬼哟~'.format(len(data)))
 going = True
 return

def lottery_start(var1, var2):
 global is_run
 if is_run:
 messagebox.showwarning('提醒', '命运的齿轮正在疯狂转动哟!')
 return
 if len(data)==0:
  messagebox.showwarning('提醒', '没有幸运儿了哟,快去抓几个吧!')
  return
 is_run = True
 var2.set('命运的齿轮开始转动起来啦~')
 lottery_roll(var1, var2)
 
def lottery_end():
 global going, is_run, data
 if is_run:
 if len(data)==0:
  messagebox.showwarning('提醒', '没有幸运儿了哟,快去抓几个吧!')
  return
 show_member = random.choice(data)
 data.remove(show_member)
 print(show_member)
 var1.set(show_member)
 going = False
 is_run = False
 else:
 messagebox.showwarning('提醒', '命运的齿轮还没开动呢!')
 
if __name__ == '__main__':
 data = getNameList()
 window = Tkinter.Tk()
 window.geometry('800x500+500+200')
 window.title('谁是幸运儿?')
 
 bg_label = Label(window, width=800, height=500, bg='#ECf5FF')
 bg_label.place(anchor=NW, x=0, y=0)

 var_title = StringVar(value='谁是幸运儿?')
 show_label1_title = Label(window, textvariable=var_title, justify='left', anchor=CENTER, width=18, height=4, bg='#ECf5FF',
   font='楷体 -40 bold', foreground='black')
 show_label1_title.place(anchor=NW, x=200, y=0)

 var1 = StringVar(value='<.<')
 show_label1 = Label(window, textvariable=var1, justify='left', anchor=CENTER, width=7, height=2, bg='#BFEFFF',
   font='楷体 -40 bold', foreground='black')
 show_label1.place(anchor=NW, x=320, y=200)
 
 var2 = StringVar(value='共有{}个幸运儿,请开始游戏'.format(len(data)))
 show_label2 = Label(window, textvariable=var2, justify='left', anchor=CENTER, width=25, height=4, bg='#ECf5FF',
   font='楷体 -25 bold', foreground='red')
 show_label2.place(anchor=NW, x=240, y=320)

 button1 = Button(window, text='开始', command=lambda: lottery_start(var1, var2), width=14, height=2, bg='#A8A8A8',
   font='宋体 -18 bold')
 button1.place(anchor=NW, x=210, y=400)

 button2 = Button(window, text='结束', command=lambda: lottery_end(), width=14, height=2, bg='#A8A8A8',
   font='宋体 -18 bold')
 button2.place(anchor=NW, x=450, y=400)
 window.mainloop()

截图:

python编写实现抽奖器

python编写实现抽奖器

python编写实现抽奖器

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

Python 相关文章推荐
解决Pycharm无法import自己安装的第三方module问题
May 18 Python
python如何创建TCP服务端和客户端
Aug 26 Python
浅谈Python在pycharm中的调试(debug)
Nov 29 Python
python射线法判断一个点在图形区域内外
Jun 28 Python
pandas DataFrame 行列索引及值的获取的方法
Jul 02 Python
Django Rest framework解析器和渲染器详解
Jul 25 Python
wxPython:python首选的GUI库实例分享
Oct 05 Python
Python数据可视化:幂律分布实例详解
Dec 07 Python
Python实现搜索算法的实例代码
Jan 02 Python
python实现快递价格查询系统
Mar 03 Python
python安装cx_Oracle和wxPython的方法
Sep 14 Python
Qt自定义Plot实现曲线绘制的详细过程
Nov 02 Python
Python字符串及文本模式方法详解
Sep 10 #Python
python raise的基本使用
Sep 10 #Python
Python常用数字处理基本操作汇总
Sep 10 #Python
Python通用唯一标识符uuid模块使用案例
Sep 10 #Python
Python编写单元测试代码实例
Sep 10 #Python
python super()函数的基本使用
Sep 10 #Python
Python如何实现机器人聊天
Sep 10 #Python
You might like
php和javascript之间变量的传递实现代码
2012/12/19 PHP
完美解决thinkphp验证码出错无法显示的方法
2014/12/09 PHP
php实现映射操作实例详解
2019/10/02 PHP
兼容IE/Firefox/Opera/Safari的检测页面装载完毕的脚本Ext.onReady的实现
2009/07/14 Javascript
dtree 网页树状菜单及传递对象集合到js内,动态生成节点
2012/04/14 Javascript
jquery定时滑出可最小化的底部提示层特效代码
2013/10/02 Javascript
Javascript学习笔记之 对象篇(一) : 对象的使用和属性
2014/06/24 Javascript
Lab.js初次使用笔记
2015/02/28 Javascript
window.open()实现post传递参数
2015/03/12 Javascript
学习JavaScript设计模式(单例模式)
2015/11/26 Javascript
jQuery+PHP+MySQL实现无限级联下拉框效果
2016/02/19 Javascript
js图片上传的封装代码
2017/08/01 Javascript
JS实现按钮颜色切换效果
2020/09/05 Javascript
vue.js-div滚动条隐藏但有滚动效果的实现方法
2018/03/03 Javascript
使用VScode 插件debugger for chrome 调试react源码的方法
2019/09/13 Javascript
vue 使用async写数字动态加载效果案例
2020/07/18 Javascript
js实现纯前端压缩图片
2020/11/16 Javascript
[02:43]DOTA2英雄基础教程 半人马战行者
2014/01/13 DOTA
[03:06]3分钟带你回顾DOTA2完美盛典&完美大师赛
2017/12/06 DOTA
[02:10]探秘浦东源深体育馆 DOTA2 Supermajor不见不散
2018/05/17 DOTA
python中的格式化输出用法总结
2016/07/28 Python
python编程实现归并排序
2017/04/14 Python
Python cookbook(数据结构与算法)将名称映射到序列元素中的方法
2018/03/22 Python
python spyder中读取txt为图片的方法
2018/04/27 Python
python高阶爬虫实战分析
2018/07/29 Python
django和vue实现数据交互的方法
2019/08/21 Python
关于Python 中的时间处理包datetime和arrow的方法详解
2020/03/19 Python
基于canvas的骨骼动画的示例代码
2018/06/12 HTML / CSS
给客户的道歉信
2014/01/13 职场文书
专科应届毕业生求职信
2014/06/04 职场文书
爱牙日活动总结
2014/08/29 职场文书
2014小学语文教学工作总结
2014/12/17 职场文书
2015年度物流工作总结
2015/04/30 职场文书
工作失职自我检讨书
2015/05/05 职场文书
于丹讲座视频观后感
2015/06/15 职场文书
导游词之上海豫园
2019/10/24 职场文书