萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> 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程序設計有所幫助。

copyright © 萬盛學電腦網 all rights reserved