python实现的简单抽奖系统实例

yipeiwu_com6年前Python基础

本文实例讲述了python实现的简单抽奖系统。分享给大家供大家参考。具体实现方法如下:

#!/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程序设计有所帮助。

相关文章

在Ubuntu系统下安装使用Python的GUI工具wxPython

(一)wxpython的安装     Ubuntu下的安装,还是比较简单的。 #使用:apt-cache search wxpython 测试一下,可以...

使用PM2+nginx部署python项目的方法示例

之前面我们使用uwsgi部署项目比较繁琐,本章节介绍使用pm2+nginx一键部署django项目 PM2的主要特性: 内建负载均衡(使用Node cluster 集群模块)...

Python使用matplotlib绘制Logistic曲线操作示例

Python使用matplotlib绘制Logistic曲线操作示例

本文实例讲述了Python使用matplotlib绘制Logistic曲线操作。分享给大家供大家参考,具体如下: 标准Logistic函数为: f(x) = 1 / ( 1 + ex...

Python实现的多进程拷贝文件并显示百分比功能示例

本文实例讲述了Python实现的多进程拷贝文件并显示百分比功能。分享给大家供大家参考,具体如下: centos7下查看cup核数: # 总核数 = 物理CPU个数 X 每颗物理CPU...

Python 实现数据结构-堆栈和队列的操作方法

队、栈和链表一样,在数据结构中非常基础一种数据结构,同样他们也有各种各样、五花八门的变形和实现方式。但不管他们形式上怎么变,队和栈都有其不变的最基本的特征,我们今天就从最基本,最简单的实...