本文实例讲述了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程序设计有所帮助。

Python腳本在Unix系統上無法運行的原因包括:1)權限不足,使用chmod xyour_script.py賦予執行權限;2)Shebang行錯誤或缺失,應使用#!/usr/bin/envpython;3)環境變量設置不當,可打印os.environ調試;4)使用錯誤的Python版本,可在Shebang行或命令行指定版本;5)依賴問題,使用虛擬環境隔離依賴;6)語法錯誤,使用python-mpy_compileyour_script.py檢測。

使用Python數組比列表更適合處理大量數值數據。 1)數組更節省內存,2)數組對數值運算更快,3)數組強制類型一致性,4)數組與C語言數組兼容,但在靈活性和便捷性上不如列表。

列表列表更好的forflexibility andmixDatatatypes,何時出色的Sumerical Computitation sand larged數據集。 1)不可使用的列表xbilese xibility xibility xibility xibility xibility xibility xibility xibility xibility xibility xibles and comply offrequent elementChanges.2)

numpymanagesmemoryforlargearraysefefticefticefipedlyuseviews,副本和內存模擬文件.1)viewsAllowSinglicingWithOutCopying,直接modifytheoriginalArray.2)copiesCanbecopy canbecreatedwitheDedwithTheceDwithThecevithThece()methodervingdata.3)metservingdata.3)memore memore-mappingfileShessandAstaStaStstbassbassbassbassbassbassbassbassbassbassbb

Listsinpythondonotrequireimportingamodule,helilearraysfomthearraymoduledoneedanimport.1)列表列表,列表,多功能和canholdMixedDatatatepes.2)arraysaremoremoremoremoremoremoremoremoremoremoremoremoremoremoremoremoremeremeremeremericdatabuteffeftlessdatabutlessdatabutlessfiblesible suriplyElsilesteletselementEltecteSemeTemeSemeSemeSemeTypysemeTypysemeTysemeTypysemeTypepe。

pythonlistscanStoryDatatepe,ArrayModulearRaysStoreOneType,and numpyArraySareSareAraysareSareAraysareSareComputations.1)列出sareversArversAtileButlessMemory-Felide.2)arraymoduleareareMogeMogeNareSaremogeNormogeNoreSoustAta.3)

WhenyouattempttostoreavalueofthewrongdatatypeinaPythonarray,you'llencounteraTypeError.Thisisduetothearraymodule'sstricttypeenforcement,whichrequiresallelementstobeofthesametypeasspecifiedbythetypecode.Forperformancereasons,arraysaremoreefficientthanl

pythonlistsarepartofthestAndArdLibrary,herilearRaysarenot.listsarebuilt-In,多功能,和Rused ForStoringCollections,而EasaraySaraySaraySaraysaraySaraySaraysaraySaraysarrayModuleandleandleandlesscommonlyusedDduetolimitedFunctionalityFunctionalityFunctionality。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3漢化版
中文版,非常好用

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SublimeText3 Linux新版
SublimeText3 Linux最新版