本文仅仅是一个娱乐项目,自己平时也偶尔买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实现福彩双色球购票系统(单机版)相关推荐

  1. [附源码]Python计算机毕业设计电影票购票系统

    项目运行 环境配置: Pychram社区版+ python3.7.7 + Mysql5.7 + HBuilderX+list pip+Navicat11+Django+nodejs. 项目技术: dj ...

  2. 练习:仿真模拟福彩双色球——中500w巨奖到底有多难?跑跑代码就晓得了。

    Python 官网:https://www.python.org/ Free:大咖免费"圣经"教程< python 完全自学教程>,不仅仅是基础那么简单-- My CS ...

  3. 【附源码】计算机毕业设计Python安卓便利猫电影购票系统安卓app14g1h(源码+程序+LW+调试部署)

    [附源码]计算机毕业设计Python安卓便利猫电影购票系统安卓app14g1h(源码+程序+LW+调试部署) 该项目含有源码.文档.程序.数据库.配套开发软件.软件安装教程 项目运行环境配置: Pyt ...

  4. [附源码]Python计算机毕业设计高铁在线购票系统

    项目运行 环境配置: Pychram社区版+ python3.7.7 + Mysql5.7 + HBuilderX+list pip+Navicat11+Django+nodejs. 项目技术: dj ...

  5. 为什么同样是上亿的并发,购票系统就要比电商系统技术挑战更大?

    同为高并发,微博热搜.天猫秒杀.12306 抢票有什么不同呢? 那接下来我们就来分别聊聊他们有什么特性~ 1.微博热搜 「微博热搜」是一个典型的读多写少场景,读今日的热点新闻,写自己的微博评论. 作为 ...

  6. java版DVD影碟片出租赁系统C/S模式 java电影购票系统课程设计

    系统采用c/s架构,当然,你可以服务端.客户端都在同一台电脑上运行: 也可以在同一局域网内服务端.客户端在其它不同电脑上运行: 如果你有云服务器,可将Service端代码部署至云服务器上,客户端在任何 ...

  7. java影院购票系统开题报告,开题报告-网上电影院购票系统的设计与实现.doc

    一.研究的目的.意义与应用前景等: 研究的目的和意义: 随着互联网技术的不断发展,各个行业都向信息化方向发展,原来的人工管理逐渐被计算机管理所替代.生活水平的提高使人们越来越注重精神层次的享受.而电影 ...

  8. java计算机毕业设计高铁在线购票系统MyBatis+系统+LW文档+源码+调试部署

    java计算机毕业设计高铁在线购票系统MyBatis+系统+LW文档+源码+调试部署 java计算机毕业设计高铁在线购票系统MyBatis+系统+LW文档+源码+调试部署 本源码技术栈: 项目架构:B ...

  9. 基于JAVA高铁在线购票系统计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA高铁在线购票系统计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA高铁在线购票系统计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语 ...

最新文章

  1. 程序员们的时间管理法则
  2. Springmvc ajax请求400
  3. Node.js—简介
  4. 用matlab求残余误差,matlab在测量误差分析中的应用
  5. boost::system::windows_error相关的测试程序
  6. AJAX应用和传统Web应用有什么不同
  7. WINDOWS XP SP2 NTFS EFS加密文件的解密案例
  8. 在ASP.NET页面中动态添加控件
  9. java实现gdal栅格矢量化,《GDAL源码剖析与开发指南》一一1.5 GDAL源码目录
  10. 网络性能测试之pathrate的安装使用
  11. 编写一个Applet,画出20条水平的、随机颜色的平行线。要求线的长度相同,整条线段都要在可视区域内
  12. C++ 类 class 构造函数 : 成员赋值 父类提前构造
  13. cocos builder中使用九宫格
  14. 数学建模笔记(七):综合评价模型
  15. STM32 电容触摸屏I2C转USB实现
  16. IP地址-子网掩码-缺省网关
  17. Snaker 用户手册
  18. android 清理缓存功能 的实现,android实现清理缓存功能
  19. 开发微信小程序推荐使用phpstorm进行开发
  20. java内部窗口无法实现,java 既不是内部命令也不是外部命令的解决办法

热门文章

  1. Audio/Video会触发的方法和事件分别有哪些
  2. 怎样便捷的退出iphone的恢复模式
  3. VC++获取CPU的名称、主频和核数(附源码)
  4. 英语专业毕业论文关于翻译方向如何进行写作,该做好哪些准备?
  5. 盘点国内那些深度学习框架:清华计图Jittor、腾讯优图NCNN、百度飞桨PaddlePaddle、阿里X-DeepLearning
  6. ​基于Verilog的DDS波形发生器的分析与实现(三角波、正弦波)
  7. Hive运行任务报错:Ended Job = job_1685266933359_0001 with errors Error during job, obtaining debugging info
  8. 什么品牌的游戏蓝牙耳机比较好?玩游戏延迟低的蓝牙耳机推荐
  9. 心态崩了,这次我真的要哭了...
  10. QT学习_06_UI设计