python實(shí)現(xiàn)的簡單抽獎(jiǎng)系統(tǒng)實(shí)例
更新時(shí)間:2015年05月22日 12:32:45 作者:小小的我
這篇文章主要介紹了python實(shí)現(xiàn)的簡單抽獎(jiǎng)系統(tǒng),涉及Python隨機(jī)數(shù)及文件操作的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了python實(shí)現(xiàn)的簡單抽獎(jiǎng)系統(tǒng)。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
#!/usr/bin/env python
#coding=utf-8
from Tkinter import *
import time
import random
class App:
def __init__(self,master):
frame = Frame(master)
frame.pack()
v = StringVar()
self.e = Entry(frame,textvariable=v,bd='5')
v.set('')
self.v = v
self.e.pack(padx=5)
self.button1 = Button(frame,text = 'start',fg='red',command=self.start_hi)
self.button1.pack(side=LEFT)
self.button2 = Button(frame,text='stop',fg = 'blue',command=self.say_stop)
self.button2.pack(side=LEFT)
self.root=master
self.stop = 0
#scrollbar = Scrollbar(frame, orient=VERTICAL)
#self.b1 = Listbox(frame, yscrollcommand=scrollbar.set)
#scrollbar.pack(side=RIGHT, fill=Y)
#self.b1.pack(side=LEFT, fill=BOTH, expand=1)
def list_star(self):
star = []
file = open('yaojiang.txt','r+')
data = file.readlines()
file.close()
for n in data:
l1 = n.split(':')
a = l1[0] + ':'+ l1[1][:4] + 'xxxx' + l1[1][8:12]
a = a.strip()
star.append(a)
return star
def start_hi(self):
self.stop = 0
#star = []
#file = open('yaojiang.txt','r+')
#data = file.readlines()
#file.close()
#for n in data:
#l1 = n.split(':')
#a = l1[0] + ':'+ l1[1][:4] + 'xxxx' + l1[1][8:12]
#a = a.strip()
#star.append(a)
star = self.list_star()
self.update_clock(star)
def say_stop(self):
self.stop = 1
#b = self.start()
def update_clock(self,star):
b = random.choice(star)
self.v.set(b)
if self.stop == 1:
return
self.root.after(50, self.update_clock,star)
root = Tk()
app = App(root)
root.mainloop()
希望本文所述對大家的Python程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- 如何基于python實(shí)現(xiàn)年會抽獎(jiǎng)工具
- Python使用Tkinter實(shí)現(xiàn)轉(zhuǎn)盤抽獎(jiǎng)器的步驟詳解
- Python實(shí)現(xiàn)的企業(yè)粉絲抽獎(jiǎng)功能示例
- 詳解用python寫一個(gè)抽獎(jiǎng)程序
- python3實(shí)現(xiàn)小球轉(zhuǎn)動抽獎(jiǎng)小游戲
- python實(shí)現(xiàn)抽獎(jiǎng)小程序
- python實(shí)現(xiàn)年會抽獎(jiǎng)程序
- python實(shí)現(xiàn)公司年會抽獎(jiǎng)程序
- 編寫python代碼實(shí)現(xiàn)簡單抽獎(jiǎng)器
相關(guān)文章
Python實(shí)現(xiàn)mysql數(shù)據(jù)庫更新表數(shù)據(jù)接口的功能
這篇文章主要給大家介紹了關(guān)于Python如何實(shí)現(xiàn)mysql數(shù)據(jù)庫更新表數(shù)據(jù)接口功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11
PyCharm實(shí)現(xiàn)本地恢復(fù)或查看歷史代碼
這篇文章主要介紹了PyCharm實(shí)現(xiàn)本地恢復(fù)或查看歷史代碼,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
python實(shí)現(xiàn)報(bào)表自動化詳解
這篇文章主要介紹了python實(shí)現(xiàn)報(bào)表自動化詳解,涉及python讀,寫excel—xlwt常用功能,xlutils 常用功能,xlwt寫Excel時(shí)公式的應(yīng)用等相關(guān)內(nèi)容,具有一定參考價(jià)值,需要的朋友可以了解下。2017-11-11
利用Python實(shí)現(xiàn)K-Means聚類的方法實(shí)例(案例:用戶分類)
k-means是發(fā)現(xiàn)給定數(shù)據(jù)集的k個(gè)簇的算法,也就是將數(shù)據(jù)集聚合為k類的算法,下面這篇文章主要給大家介紹了關(guān)于利用Python實(shí)現(xiàn)K-Means聚類的相關(guān)資料,需要的朋友可以參考下2022-05-05
詳解Python中的內(nèi)建函數(shù),可迭代對象,迭代器
這篇文章主要介紹了Python內(nèi)建函數(shù),可迭代對象,迭代器,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

