python編寫實(shí)現(xiàn)抽獎(jiǎng)器
更新時(shí)間:2020年09月10日 14:04:10 作者:江湖人稱黑哥
這篇文章主要為大家詳細(xì)介紹了python編寫實(shí)現(xiàn)抽獎(jiǎng)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了python編寫實(shí)現(xiàn)抽獎(jiǎng)器的具體代碼,供大家參考,具體內(nèi)容如下
# 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('還有{}個(gè)小幸運(yùn)鬼喲~'.format(len(data))) going = True return def lottery_start(var1, var2): global is_run if is_run: messagebox.showwarning('提醒', '命運(yùn)的齒輪正在瘋狂轉(zhuǎn)動(dòng)喲!') return if len(data)==0: messagebox.showwarning('提醒', '沒有幸運(yùn)兒了喲,快去抓幾個(gè)吧!') return is_run = True var2.set('命運(yùn)的齒輪開始轉(zhuǎn)動(dòng)起來啦~') lottery_roll(var1, var2) def lottery_end(): global going, is_run, data if is_run: if len(data)==0: messagebox.showwarning('提醒', '沒有幸運(yùn)兒了喲,快去抓幾個(gè)吧!') 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('提醒', '命運(yùn)的齒輪還沒開動(dòng)呢!') if __name__ == '__main__': data = getNameList() window = Tkinter.Tk() window.geometry('800x500+500+200') window.title('誰是幸運(yùn)兒?') bg_label = Label(window, width=800, height=500, bg='#ECf5FF') bg_label.place(anchor=NW, x=0, y=0) var_title = StringVar(value='誰是幸運(yùn)兒?') 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='共有{}個(gè)幸運(yùn)兒,請(qǐng)開始游戲'.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='結(jié)束', command=lambda: lottery_end(), width=14, height=2, bg='#A8A8A8', font='宋體 -18 bold') button2.place(anchor=NW, x=450, y=400) window.mainloop()
截圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 用Python實(shí)現(xiàn)一個(gè)簡(jiǎn)單的抽獎(jiǎng)小程序
- Python關(guān)于抽獎(jiǎng)系統(tǒng)的思考與設(shè)計(jì)思路
- 使用Python可設(shè)置抽獎(jiǎng)?wù)邫?quán)重的抽獎(jiǎng)腳本代碼
- 基于Python實(shí)現(xiàn)評(píng)論區(qū)抽獎(jiǎng)功能詳解
- Python制作一個(gè)隨機(jī)抽獎(jiǎng)小工具的實(shí)現(xiàn)
- Python中實(shí)現(xiàn)限定抽獎(jiǎng)次數(shù)的機(jī)制的項(xiàng)目實(shí)踐
相關(guān)文章
Python類中的裝飾器在當(dāng)前類中的聲明與調(diào)用詳解
這篇文章主要介紹了Python類中的裝飾器在當(dāng)前類中的聲明與調(diào)用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-04-04python 繪圖模塊matplotlib的使用簡(jiǎn)介
這篇文章主要介紹了python 繪圖模塊matplotlib的使用簡(jiǎn)介,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-03-03Python實(shí)現(xiàn)簡(jiǎn)易Web爬蟲詳解
這篇文章主要介紹了Python實(shí)現(xiàn)簡(jiǎn)易Web爬蟲詳解,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01在Python中封裝GObject模塊進(jìn)行圖形化程序編程的教程
這篇文章主要介紹了在Python中封裝GObject模塊進(jìn)行圖形化程序編程的教程,本文來自于IBM官方網(wǎng)站技術(shù)文檔,需要的朋友可以參考下2015-04-04Python 在 VSCode 中使用 IPython Kernel 的方法詳解
這篇文章主要介紹了Python 在 VSCode 中使用 IPython Kernel 的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09python 30行代碼實(shí)現(xiàn)螞蟻森林自動(dòng)偷能量
這篇文章主要介紹了python 30行代碼實(shí)現(xiàn)螞蟻森林自動(dòng)偷能量的方法,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-02-02