A case of lottery machine selector implemented by Python

Source: Internet
Author: User
Tags pack

This paper illustrates the method of implementing the lottery machine by Python. Share to everyone for your reference. The implementation methods are as follows:

?

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 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= ' Shuangse Qiu ', fg= ' Red ', Font=tkfont.font (family= ' Microsoft Ya-black ', size=20), width=20, command= self.creatdouble) Self.button1.pack (side=left) Self.button2 = Button (frame[1), text= ' Grand Lotto ', fg= ' blue ', Tkfont.font (family= ' Microsoft Youngor, size=20), width=20, Command=self.creatdaletou) self.button2.pack (side=left) Self.button3 = Button (frame[2], text= ' empty ', Font=tkfont.font (family= ' Microsoft Ya-black ', 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 to 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 (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 (5) Afterarea = Self.creatrandum (2) ballstr = ' For i in BEFOREAREA:BALLSTR = Ballstr + str (i) + ' ballstr = ballstr + ' | ' for i in afterarea:ballstr = Ballstr + St R (i) + ' ballstr = ballstr + ' n ' Self.text.insert (1.0, ballstr) root = Tk () app = app (root) root.title (' Lottery Machine selector ') Root.mai Nloop ()

The results of the operation are as follows:

I hope this article will help you with your Python programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.