python编写实现抽奖器

作者:江湖人称黑哥 时间:2023-02-25 00:44:45 

本文实例为大家分享了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编写实现抽奖器

来源:https://blog.csdn.net/qq_40088207/article/details/108472191

标签:python,抽奖器
0
投稿

猜你喜欢

  • python 识别登录验证码图片功能的实现代码(完整代码)

    2021-03-14 23:03:40
  • 直接生成XML的Google SiteMap的asp代码

    2007-08-17 13:44:00
  • Oracle收购TimesTen 提高数据库软件性能

    2010-07-21 13:03:00
  • Python3从零开始搭建一个语音对话机器人的实现

    2023-11-15 05:52:12
  • 在Python中操作字符串之rstrip()方法的使用

    2022-03-22 18:34:36
  • Django+RestFramework API接口及接口文档并返回json数据操作

    2021-05-29 21:43:57
  • python3+PyQt5 实现Rich文本的行编辑方法

    2023-09-29 14:37:47
  • pandas string转dataframe的方法

    2021-08-15 14:47:04
  • Python代码库之Tuple如何append添加元素问题

    2021-10-02 07:13:34
  • Python 高级变量之字典和字符串详解

    2021-11-16 19:36:35
  • 安装MySQL后include目录下没有找到libmysql.lib

    2024-01-25 17:55:13
  • Node.js中的process.nextTick使用实例

    2024-05-08 09:36:18
  • Javascript实现数组中的元素上下移动

    2024-04-22 22:36:16
  • 轻松实现javascript数据双向绑定

    2024-03-26 20:23:50
  • Python实现快速多线程ping的方法

    2023-05-28 21:35:09
  • python数值基础知识浅析

    2021-12-10 07:07:49
  • php引用和拷贝的区别知识点总结

    2023-11-15 03:39:48
  • MySQL查询条件中放置on和where的区别分析

    2024-01-25 00:22:51
  • 贝聿铭写给年轻设计师的十点忠告

    2010-01-24 18:46:00
  • 白话Block Formatting Context

    2010-08-03 12:36:00
  • asp之家 网络编程 m.aspxhome.com