python实现的彩票机选器实例

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

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

Posted in 未分类