脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python实现的彩票机选器实例

Python实现的彩票机选器实例

2020-07-16 10:33蛋疼的淡定哥 Python

这篇文章主要介绍了Python实现彩票机选器的方法,可以模拟彩票号码的随机生成功能,需要的朋友可以参考下

本文实例讲述了Python实现彩票机选器的方法。分享给大家供大家参考。具体实现方法如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf8 -*-
from Tkinter import *
import tkFont
import random
class App: 
  def __init__(self, master) :
    frame = [Frame() for i in range(4)]
    for i in range(4):
      frame[i] = Frame(master)
      frame[i].pack()
    self.button1 = Button(frame[0], text='双色球', fg='red', font=tkFont.Font(family='微软雅黑',size=20),width=20, command=self.creatDouble)
    self.button1.pack(side=LEFT)
    self.button2 = Button(frame[1], text='大乐透', fg='blue',font=tkFont.Font(family='微软雅黑',size=20),width=20, command=self.creatDaLeTou)
    self.button2.pack(side=LEFT)
    self.button3 = Button(frame[2], text='清空', font=tkFont.Font(family='微软雅黑',size=20),width=20, command=self.clearall)
    self.button3.pack()
    self.text = Text(frame[3], width=53, height=15)
    self.scroll = Scrollbar(frame[3], width=4, command=self.text.yview)
    self.text.configure(yscrollcommand=self.scroll.set)
    self.scroll.pack(side=RIGHT, fill=Y)
    self.text.pack(side=LEFT)
  def say_hi(self):
    print 'hello world'
  def clearall(self):
    self.text.delete('1.0',END)
  def creatRandum(self, rangeSize, arrSize):
    arr = [0 for i in range(0,arrSize)]
    rangeArr = [x + 1 for x in range(rangeSize)]
    for i in range(len(arr)) :
      arr[i] = rangeArr[random.randint(0, len(rangeArr) - 1)]
      rangeArr.remove(arr[i])
    arr.sort()
    return arr
  def creatDouble(self):
    redball = self.creatRandum(33, 6)
    blueball = random.randint(1,16)
    ballstr = ''
    for i in redball :
      ballstr = ballstr + str(i) + ' '
    ballstr = ballstr + '|' + str(blueball) + '\n'
    self.text.insert(1.0, ballstr)
  def creatDaLeTou(self):
    beforeArea = self.creatRandum(35, 5)
    afterArea = self.creatRandum(12, 2)
    ballstr = ''
    for i in beforeArea :
      ballstr = ballstr + str(i) + ' '
    ballstr = ballstr + '|'
    for i in afterArea :
      ballstr = ballstr + str(i) + ' '
    ballstr = ballstr + '\n'
    self.text.insert(1.0, ballstr)
root = Tk()
app = App(root)
root.title('彩票机选器')
root.mainloop()

运行效果如下所示:

Python实现的彩票机选器实例

希望本文所述对大家的Python程序设计有所帮助。

延伸 · 阅读

精彩推荐