python3.7实现福彩双色球购票系统(单机版)
本文仅仅是一个娱乐项目,自己平时也偶尔买2元彩票,但基本没有中过奖,这里实现一下双色球的中奖流程,没事可以自己YY一下,说不定在自己系统中了奖,再去买一张就真的中了呢?咳咳,言归正传,中奖这事情是无法强求的,还是专心研究技术吧。
本文的界面采用tkinter实现,首先是注册登陆流程,这里主要是用sqllite保存用户的数据。用户表也很简单,由账户,密码和金币组成。
注册成功后,系统自动赠送1000金币。
然后注册成功后自动跳转登陆界面,登陆成功后就进入主界面,然后输入7位双色球数字,点击自选一注购买,再点击开奖就可以开玩啦,反正我YY了一个晚上也没有中大奖
:
最后源码分享给各位看官:
# coding=utf-8
import tkinter as tk
import sqlite3
from tkinter.messagebox import *
import os
import traceback
import itertools
import random
import timefrom tkinter import scrolledtextglobal scrdef buyOneSecond():# t1 = threading.Thread(target=threadToUpdate)# t1.setDaemon(True)# t1.start()numStr = oneSecond.get()print("buyOneSecond:"+numStr)numList = numStr.split()print(numList)if len(numList) != 7:showerror("错误","输入数量不对,请核对")returntry:buyNum = []for s in numList:buyNum.append(int(s))lastNum = buyNum[len(buyNum)-1]buyNum.remove(lastNum)if len(set(buyNum))!=6:showerror("错误","输入数字重复,请核对")returnbuyNum = sorted(buyNum)global buyOnebuyOne = []buyOne.append(buyNum)buyOne.append(lastNum)print(buyNum)print(buyOne)except:print('traceback.format_exc():\n%s' % traceback.format_exc())showerror("错误","输入不合法字符,请核对!")returndef addLuckMoney(money):updateMoney = int(moneyNumber.get())+moneymoneyNumber.set(updateMoney)myMoney.set(lName.get()+"的金币 "+str(moneyNumber.get()))connection = sqlite3.connect("lotteryTest.db",check_same_thread = False)mycursor = connection.cursor()connection.execute("BEGIN TRANSACTION;") # 关键点sql = "update userInfo set money='"+str(moneyNumber.get())+"' where user='"+lName.get().strip()+"'"print(sql)mycursor.execute(sql)connection.execute("COMMIT;") #关键点connection.commit()mycursor.close()# def startLottery1():
# i=0
# while i<100:
# i+=1
# time.sleep(0.1)
# startLottery()
# returndef startLottery():print(buyOne)scr.insert(tk.END,str(buyOne))updateMoney = int(moneyNumber.get())-2moneyNumber.set(updateMoney)myMoney.set(lName.get()+"的金币 "+str(moneyNumber.get()))connection = sqlite3.connect("lotteryTest.db",check_same_thread = False)mycursor = connection.cursor()connection.execute("BEGIN TRANSACTION;") # 关键点sql = "update userInfo set money='"+str(moneyNumber.get())+"' where user='"+lName.get().strip()+"'"print(sql)mycursor.execute(sql)connection.execute("COMMIT;") #关键点connection.commit()mycursor.close()frontNum = []i=0while i<33:i+=1frontNum.append(i)backNum = []i=0while i<16:i+=1backNum.append(i)print(frontNum)print(backNum)lotteryNum = []#最终开奖号码lotteryFrontListAll = list(itertools.combinations(frontNum,6))randomFront = random.randint(0,len(lotteryFrontListAll)-1)lotteryFront = lotteryFrontListAll[randomFront]print(lotteryFront)lotteryNum.append(lotteryFront)lotteryBackListAll = list(itertools.combinations(backNum,1))randomBack = random.randint(0,len(lotteryBackListAll)-1)lotteryBack = lotteryBackListAll[randomBack]print(lotteryBack)lotteryNum.append(lotteryBack)print(lotteryNum)scr.insert(tk.END,str(lotteryNum)+"\n")if len(buyOne)==0:returnlotteryFrontSum=0for s in lotteryFront:if s in buyOne[0]:lotteryFrontSum+=1lotteryBackSum = 0if lotteryBack==buyOne[1]:lotteryBackSum = 1print(buyOne[0])print(lotteryFront)print(buyOne[1])print(lotteryBack)print("lotteryFrontSum "+str(lotteryFrontSum))print("lotteryBackSum "+str(lotteryBackSum))if (lotteryFrontSum==0 or lotteryFrontSum==1 or lotteryFrontSum==2) and lotteryBackSum==1:print("六等奖")showinfo("提示","恭喜中六等奖5金币")addLuckMoney(5)elif(lotteryFrontSum==3 and lotteryBackSum==1) or (lotteryFrontSum==4 and lotteryBackSum==0):print("五等奖")showinfo("提示","恭喜中五等奖10金币")addLuckMoney(10)elif(lotteryFrontSum==4 and lotteryBackSum==1)or(lotteryFrontSum==5 and lotteryBackSum==0):print("四等奖")showinfo("提示","恭喜中四等奖200金币")addLuckMoney(200)elif(lotteryFrontSum==5 and lotteryBackSum==1):print("三等奖")showinfo("提示","恭喜中三等奖3000金币")addLuckMoney(3000)elif(lotteryFrontSum==6 and lotteryBackSum==0):print("二等奖")showinfo("提示","恭喜中二等奖50万金币")addLuckMoney(500000)elif(lotteryFrontSum==6 and lotteryBackSum==1):print("一等奖")showinfo("提示","恭喜中一等奖1000万金币")addLuckMoney(10000000)else:print("未中奖")showinfo("提示","未中奖")returnclass RegisterPage(object):def __init__(self, master=None):self.root = master #定义内部变量rootself.root.geometry('%dx%d' % (300, 250)) #设置窗口大小self.page = tk.Frame(self.root) #创建Frameself.page.pack()self.username = tk.StringVar()self.password = tk.StringVar()self.surePassword = tk.StringVar()tk.Label(self.page).grid(row=0, stick=tk.W)tk.Label(self.page, text = '账户: ').grid(row=1, stick=tk.W, pady=10)tk.Entry(self.page, textvariable=self.username).grid(row=1, column=1, stick=tk.E)tk.Label(self.page, text = '密码: ').grid(row=2, stick=tk.W, pady=10)tk.Entry(self.page, textvariable=self.password, show='*').grid(row=2, column=1, stick=tk.E)tk.Label(self.page, text = '确认密码: ').grid(row=3, stick=tk.W, pady=10)tk.Entry(self.page, textvariable=self.surePassword, show='*').grid(row=3, column=1, stick=tk.E)tk.Button(self.page, text='注册', command=self.registerAccount).grid(row=4, column=1, stick=tk.W)def registerAccount(self):#print("注册账号 "+self.username.get()+" 密码:"+self.password.get())if self.password.get()!=self.surePassword.get():showerror("错误","两次密码输入不一致")elif self.username.get() == "" or self.password.get() == "" or self.surePassword.get() == "":showerror("错误","账号密码输入不能为空")elif len(self.password.get())<6:showerror("错误","密码不能小于6个字符")else:print("开始注册流程")try:connection = sqlite3.connect("lotteryTest.db",check_same_thread = False)mycursor = connection.cursor()print("111")connection.execute("BEGIN TRANSACTION;") # 关键点print("222")insert_sql ="insert into userInfo (user,pwd,money) values ('"+self.username.get()+"','"+self.password.get()+"','1000')"print(insert_sql)mycursor.execute(insert_sql)connection.execute("COMMIT;") #关键点connection.commit()mycursor.close()showinfo("提示","恭喜注册成功,获得1000金币")self.page.destroy()LoginPage(root)except:showerror("错误","该账号已存在")passclass LoginPage(object):def __init__(self, master=None):self.root = master #定义内部变量rootself.root.geometry('%dx%d' % (300, 180)) #设置窗口大小self.username = tk.StringVar()self.password = tk.StringVar()self.createPage()def createPage(self):self.page = tk.Frame(self.root) #创建Frameself.page.pack()tk.Label(self.page).grid(row=0, stick=tk.W)tk.Label(self.page, text = '账户: ').grid(row=1, stick=tk.W, pady=10)tk.Entry(self.page, textvariable=self.username).grid(row=1, column=1, stick=tk.E)tk.Label(self.page, text = '密码: ').grid(row=2, stick=tk.W, pady=10)tk.Entry(self.page, textvariable=self.password, show='*').grid(row=2, column=1, stick=tk.E)tk.Button(self.page, text='登陆', command=self.loginCheck).grid(row=3,stick=tk.W, pady=10)tk.Button(self.page, text='注册', command=self.toRegisterPage).grid(row=3, column=1,stick=tk.E)def toRegisterPage(self):self.page.destroy()RegisterPage(root)def loginCheck(self):name = self.username.get()secret = self.password.get()if self.username.get() == "" or self.password.get() == "":showerror("错误","账号密码输入不能为空")returnmycursor = connection.cursor()sql = "select user,pwd from userInfo where user='"+name+"'"print(sql)result = mycursor.execute(sql)userList = result.fetchall()if len(userList)==0:showerror("错误","用户名不存在")returnif userList[0].__contains__(name) and userList[0].__contains__(secret):print("登陆成功")self.page.destroy()lName.set(name)lPwd.set(secret)MainPage(root)else:showerror(title='错误', message='账号或密码错误!')mycursor.close()passclass MainPage(object):def __init__(self, master=None):self.root = master #定义内部变量rootself.root.geometry('%dx%d' % (700, 600)) #设置窗口大小mycursor = connection.cursor()sql = "select money from userInfo where user='"+lName.get()+"'"print(sql)result = mycursor.execute(sql)moneyNumber.set(result.fetchall()[0][0])#得到的list[0]是一个元祖,应该取list[0][0]就是元祖的第一个值了。print(moneyNumber.get())myMoney.set(lName.get()+"的金币 "+str(moneyNumber.get()))showMyMoney = tk.Label(root,textvariable=myMoney,bd=2,width=15,fg="blue",font = 'Helvetica -12')showMyMoney.place(x=0,y=5,anchor='nw')oneSecondInput = tk.Entry(root,textvariable=oneSecond,show=None,foreground = 'blue',font = ('Helvetica', '13'),insertbackground = 'green',width=20)oneSecondInput.place(x=130, y=5, anchor='nw')updateBtn = tk.Button(root, text="自选一注购买",bd=2,width=11,font = 'Helvetica -13',command=buyOneSecond)updateBtn.place(x=320, y=5, anchor='nw')startBtn = tk.Button(root, text="开奖",bd=2,width=11,font = 'Helvetica -13',command=startLottery)startBtn.place(x=520, y=5, anchor='nw')global scrscr = scrolledtext.ScrolledText(root, width=50, height=20,font=("隶书",18)) #滚动文本框(宽,高(这里的高应该是以行数为单位),字体样式)scr.place(x=50, y=50) #滚动文本框在页面的位置mycursor.close()passdef createTable():try:connection = sqlite3.connect("lotteryTest.db",check_same_thread = False)mycursor = connection.cursor()connection.execute("BEGIN TRANSACTION;") # 关键点userTable = "create table userInfo('user' text PRIMARY KEY not null,'pwd' text not null,'money' text not null)"mycursor.execute(userTable)#transactionTable = "create table transInfo('user' text PRIMARY KEY not null,'second' text not null)"#mycursor.execute(transactionTable)connection.execute("COMMIT;") #关键点connection.commit()mycursor.close()except:print('traceback.format_exc():\n%s' % traceback.format_exc())showerror("错误提示","数据库发生异常...")returnpassroot = tk.Tk() # 初始化Tk()
root.title("模拟福彩购彩交易系统") # 设置窗口标题
isExistDB = os.path.exists("lotteryTest.db")
connection = sqlite3.connect("lotteryTest.db",check_same_thread = False)
if isExistDB==False:createTable()
buyOne = []
moneyNumber = tk.StringVar()
lName = tk.StringVar()
lPwd = tk.StringVar()
oneSecond = tk.StringVar()
myMoney = tk.StringVar()
LoginPage(root)
root.mainloop() # 进入消息循环
python3.7实现福彩双色球购票系统(单机版)相关推荐
- [附源码]Python计算机毕业设计电影票购票系统
项目运行 环境配置: Pychram社区版+ python3.7.7 + Mysql5.7 + HBuilderX+list pip+Navicat11+Django+nodejs. 项目技术: dj ...
- 练习:仿真模拟福彩双色球——中500w巨奖到底有多难?跑跑代码就晓得了。
Python 官网:https://www.python.org/ Free:大咖免费"圣经"教程< python 完全自学教程>,不仅仅是基础那么简单-- My CS ...
- 【附源码】计算机毕业设计Python安卓便利猫电影购票系统安卓app14g1h(源码+程序+LW+调试部署)
[附源码]计算机毕业设计Python安卓便利猫电影购票系统安卓app14g1h(源码+程序+LW+调试部署) 该项目含有源码.文档.程序.数据库.配套开发软件.软件安装教程 项目运行环境配置: Pyt ...
- [附源码]Python计算机毕业设计高铁在线购票系统
项目运行 环境配置: Pychram社区版+ python3.7.7 + Mysql5.7 + HBuilderX+list pip+Navicat11+Django+nodejs. 项目技术: dj ...
- 为什么同样是上亿的并发,购票系统就要比电商系统技术挑战更大?
同为高并发,微博热搜.天猫秒杀.12306 抢票有什么不同呢? 那接下来我们就来分别聊聊他们有什么特性~ 1.微博热搜 「微博热搜」是一个典型的读多写少场景,读今日的热点新闻,写自己的微博评论. 作为 ...
- java版DVD影碟片出租赁系统C/S模式 java电影购票系统课程设计
系统采用c/s架构,当然,你可以服务端.客户端都在同一台电脑上运行: 也可以在同一局域网内服务端.客户端在其它不同电脑上运行: 如果你有云服务器,可将Service端代码部署至云服务器上,客户端在任何 ...
- java影院购票系统开题报告,开题报告-网上电影院购票系统的设计与实现.doc
一.研究的目的.意义与应用前景等: 研究的目的和意义: 随着互联网技术的不断发展,各个行业都向信息化方向发展,原来的人工管理逐渐被计算机管理所替代.生活水平的提高使人们越来越注重精神层次的享受.而电影 ...
- java计算机毕业设计高铁在线购票系统MyBatis+系统+LW文档+源码+调试部署
java计算机毕业设计高铁在线购票系统MyBatis+系统+LW文档+源码+调试部署 java计算机毕业设计高铁在线购票系统MyBatis+系统+LW文档+源码+调试部署 本源码技术栈: 项目架构:B ...
- 基于JAVA高铁在线购票系统计算机毕业设计源码+数据库+lw文档+系统+部署
基于JAVA高铁在线购票系统计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA高铁在线购票系统计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语 ...
最新文章
- flink on yarn部分源码解析 (FLIP-6 new mode)
- java从Object类型转换成double类型
- linux管理员工作目录,密码管理员 - FPM2
- javaSE基础代码案例
- 机器学习 | 梯度下降原理及Python实现
- 【BZOJ1051】受欢迎的牛,tarjan缩点重构图
- opencv 轮廓特征
- matplotlib.text.Text
- sphereface conv64
- jsapi微信扫一扫
- 21天学通JAVA:类的定义和对象的创建
- Matter-JS friction 摩擦力
- 电子书籍下载第一强贴
- C语言使用信号量(Linux)
- 【Linux实验】LINUX系统的文件操作命令
- Android 出海 Admob 踩坑
- 2019年杭电计算机考研经验
- DNA存储,拯救人类数据危机的良方?
- myCPUZ (未完待续)
- ModemManager 1.10发布
热门文章
- eclipse的插件开发工具下载
- Linux NetworkManager 的使用方法(nmcli和nmtui)
- Naxsi 配置白名单
- Appium之Doctor报错:iOS Could not detect Mac OS X Version from sw_vers output: '10.12.5 '的解决方法
- [02-14] 绿色免费软件更新
- python oop求三角形面积公式_Python面向对象编程-OOP
- 解决laravel Use of undefined constant JSON_INVALID_UTF8_SUBSTITUTE - assumed ‘JSON_INVAL
- Springboot旅游社交平台9k9sq计算机毕业设计-课程设计-期末作业-毕设程序代做
- STM32F103系列_OLED屏幕(SSD1306、SSD1315驱动)SPI驱动【DMA】(高刷)
- [转帖]老鸟运维的下场