关于塔罗牌摆放的小程序------python入门案例

关于塔罗牌摆放的小程序------python入门案例


在这里插入图片描述

前言

  • 本文主要分享基于python开发的小程序,用于实现随机抽取塔罗牌并按特定需求摆放位置进行展示,之后从数据库中获取每张的解释与分类推理含义。
  • 通过本文你将收获基础的python语法规则、常用包**(opencv2、pIL、numpy、pymysql)**的调用、本地文件的操作、简单一个程序流程。作为一个简化的入门学习案例,可分解进行学习掌握。本文涉及的sql数据库构建、调用会在后续的博文中更新。

程序开发原因(待更新)

程序流程

在这里插入图片描述

结果展示

  • 说明:由于商业保密(。。。),数据库调用过程的结果只有相关代码,不进行展示
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

函数从零讲解

  • 说明: 完整代码在下文中展示。需要直接运行尝试的可以下个相关上传的文件/百度云盘/github。本节是分步讲解(慢慢更新)。运行环境python3.9、pycharm 2020.4
  • 导入使用的包
  1. 图像相关包 2数学包 3本地文件操作 4数据库包
import cv2
import numpy as np
import PIL.Image as img
import os,sys
import pymysql
  • 初始输入信息用于数据库的读取过程与保存
# #输入执行信息
a1_1_name = 'name'
a1_1_sex = 1 # 分类标签 [1,2]
a1_1_type = '工作'  #工作 学习 爱情 未来发展
a1_1_type_1 = 'a'   # 分类标签 a b c d
a1_1_num = 3  # 牌阵数目 [3,5,8]
a1_1_weixie = '12345678'  # 微信号
a1_1_Divination_content = '我想知道我能当上逗逼吗?'
a14_2 = ["bake.jpg"]  # 背景图片的地址
name ='最终测试' # 保存图片的名字
danhao = 1     # 问题储存记录
mima ='1602480875' # 密码
file_photo_dr = 'F:/软件安装包/项目文件/不更新/占卜/简化版/tupian/' # 卡图文件地址
  • 运行随机生成过程
#运行函数
if __name__ == '__main__':
    pan_duan_sex_data(a1_1_sex,a1_1_num)
    [a11_1,b11_1]=rand_num(a1_1_num) #返回翻转矩阵和随机数矩
  • 随机生成一个2*3的随机矩阵,第一行为(1:156)塔罗牌数目,第2行为0或1的随机数(逆位或正位)。
def rand_num(num_card):
    #num_card=input("请输入牌阵数目=")
    num_card=int(num_card)
    cx=np.zeros(int(num_card))
    cx_1=np.zeros(int(num_card))
    num_card_1=int(num_card)
    for i in range(num_card_1):
        cx[int(i)]=np.random.randint(1,156) #产生随机数
        while cx[i] in cx[1:i-1] and cx[i] in cx[1:i-1]-78:
            cx[int(i)] = np.random.randint(1, 156)
        if cx[int(i)]>78:
            cx_1[int(i)]=1
        else:
            cx_1[int(i)] =0
    print('产生的卡片序号分别是卡片=%s'%\
          cx)
    return cx_1,cx #产生随机数和结果
  • 读取本地卡图地址(数据库中调用、本地文件读取)
  • 本地读取
        ptos_flies, root_name = file_name(file_photo_dr)
        num_x = ptos_flies.__len__()
        ax_name = list(range(num_x))
        ptos_flies.sort();
        for j in range(num_x-1):
            ax_name[j] = root_name + ptos_flies[j]
        # print(ax_name)
        if (i<=78):
            a12_1=ax_name[int(i)]
        else:
            a12_1 = ax_name[int(i/2)]
def file_name(file_dir):
    for root,dirs,files in os.walk(file_dir):
        return files, root
  • 数据库读取(提供的简化学习版不执行)
def data_Write_1(q_1, type_1, type_a, mode, mima):
    db= pymysql.connect(host='localhost', user='root', password=mima, database='牌库数据')
    cursor = db.cursor()
    if mode == 3:
        cc_1 = cursor.execute("INSERT INTO `牌库数据`.`数据原始问题集合`(`问题`, `分类`, `分类标签`) VALUES ('%s', '%s', '%s') " % \
                            (q_1,type_1,type_a))  # 写入数据
        if cc_1 == 1:
            print("成功保存问题数据 %s条" % \
                 cc_1)
    db.commit()
    db.close()
# 数据输入判断
def pan_duan_sex_data(a1_1_sex,a1_1_num):
    data_kongzhi_1=[1,2]
    data_kongzhi_2=[3,5,8]
    if a1_1_sex in data_kongzhi_1 :
        print("输入性别数据数据无错误")
    else:
         print("输入的性别数据存在问题,已经停止运行")
         sys.exit(0) #停止当前运行
    if a1_1_num in data_kongzhi_2 :
        print("输入牌阵数据数据无错误")
    else:
         print("输入的牌阵数据存在问题,已经停止运行")
         sys.exit(0) #停止当前运行
#分类数据录入函数
def pan_none(type,gg,a1_1_type):
    mode=1
    if type == None:
        print('--------------------------------------------------')
        print('是否需要补充此记录的数据')
        print('--------------------------------------------------')
        ax_1 = input("是否补充?1补充,2不补充=====")
        if int(ax_1) == 1:
            print('补充')
            data_Write(gg,a1_1_type,mode)
        else:
            print('不补充')
#数据分类读取程序
def data_Write(gg,a1_1_type,mode,mima):
    db= pymysql.connect(host='localhost',
                                 user='root',
                                 password=mima,
                                 database='牌库数据')
    cursor = db.cursor()
    if mode==1:
        data_1 = input("请输入补充数据==")
        cc_1 = cursor.execute('UPDATE 牌分类牌意 SET %s = "%s" where 牌序号= %s' % \
                            (a1_1_type, data_1, gg))
        print("修改的数据条数= %s" % \
              cc_1)
        db.commit()
    if mode==2:
        jj=cursor.execute('select * from 牌分类牌意 where 牌序号= %s;'%\
                      gg )#gg输入id
    #返回查找到数据数目
        print("分类牌查询到的解释数据条数= %s"%\
              jj)
        db.commit()
        results = cursor.fetchall()
        try:
            for row in results:
                  id= row[0]
                  type1=row[1]
                  type2 = row[2]
                  type3=row[3]
                  type4 = row[4]
            ss_1 = ["学习"]
            ss_2 = ["工作"]
            ss_3 = ["爱情"]
            ss_4 = ["未来发展"]
            if a1_1_type in ss_1:
                print("学习类别下的解释:——————%s" % \
                      type1)
                pan_none(type1,gg,a1_1_type,)
            if a1_1_type in ss_2:
                print("工作类别下的解释:——————%s" % \
                      type2)
                pan_none(type2,gg,a1_1_type)
            if a1_1_type in ss_3:
                print("爱情类别下的解释:——————%s" % \
                      type3)
                pan_none(type3,gg,a1_1_type)
            if a1_1_type in ss_4:
                print("未来发展类别下的解释:——————%s" % \
                      type4)
                pan_none(type4,gg,a1_1_type)
            return id, type1, type2, type3, type4
        except:
            print("牌分类读取存在问题")
    db.close()
    # 关闭数据库连接
#随机数产生函数
  • 结果绘制与保存
def crade_buzhi(cc_no_1,cc_no_2,cc_no_3,cc_no_4,name):
    if len(cc_no_1) != len(cc_no_2):
        print("输入的数据数目有误")
        os.system("pause")
    if cc_no_3 == 3:
        print("执行的是3张牌阵")
        for i in range(3):
            if i == 0:
                img2 = img.open(cc_no_4)
                # img2 = cv2.imread(cc_no_4[i])  # 背景 仅仅第一次运行时
                # img_2 = img2.resize(img2, (684, 589))  # 改变背景的长宽 仅仅第一次运行时‘
                img_2 = img2.resize((684, 589),img.ANTIALIAS)
                # img_2.save("ceshi2.jpg")
                # cv2.imwrite("ceshi2.jpg", img_2)
            img1 = img.open(cc_no_1[i])  # 读取卡片地址
            [rows, cols]= img1.size  # 读取卡片的长宽
            img_1 = img1.resize( (int(rows / 2), int(cols / 2)))  # 改变卡片的长宽
            if cc_no_2[i] == 1:
                img_1.transpose(img.ROTATE_180)
                # img_1 = cv2.flip(img_1, -1)  # 但为逆位旋转180度
            # cv2.imwrite("ceshi.jpg", img_1)
            # img_1_1 = img.open('ceshi.jpg')
            img_1_1 = img_1
            # img_2_1 = img.open('ceshi2.jpg')
            img_2_1 = img_2
            cc_no = i + 1
            if cc_no == 1:
                a1_where = (100, 200)
                img_2_1.paste(img_1_1, a1_where)
            elif cc_no == 2:
                a2_where = (260, 200)
                img_2_1.paste(img_1_1, a2_where)
            elif cc_no == 3:
                a3_where = (420, 200)
                img_2_1.paste(img_1_1, a3_where)

            img_2_1.save("ceshi2.jpg")
    if cc_no_3==5:
        print("执行的是5张牌阵")
        for i in range(5):
            if i==0:
                img2 = cv2.imread(cc_no_4[i]) # 背景 仅仅第一次运行时
                img_2 = cv2.resize(img2, (601, 733))  # 改变背景的长宽 仅仅第一次运行时‘
                cv2.imwrite("ceshi2.jpg", img_2)
            img1 = cv2.imread(cc_no_1[i])  # 读取卡片地址
            rows, cols = img1.shape[0:2]   #读取卡片的长宽
            img_1 = cv2.resize(img1, (int(cols / 2), int(rows / 2)))  # 改变卡片的长宽
            if cc_no_2[i]==1:
                img_1 = cv2.flip(img_1, -1)  # 但为逆位旋转180度
            cv2.imwrite("ceshi.jpg",img_1)
            img_1_1=img.open('ceshi.jpg')
            img_2_1 = img.open('ceshi2.jpg')
            cc_no=i+1
            if cc_no==3:
                a1_where=(120,50)
                img_2_1.paste(img_1_1,a1_where)
            elif cc_no == 5:
                a2_where = (371, 50)
                img_2_1.paste(img_1_1,a2_where)
            elif cc_no==2:
                a3_where=(177,280)
                img_2_1.paste(img_1_1,a3_where)
            elif cc_no==4:
                a4_where=(330,280)
                img_2_1.paste(img_1_1,a4_where)
            elif cc_no==1:
                a5_where=(248,506)
                img_2_1.paste(img_1_1,a5_where)
            img_2_1.save("ceshi2.jpg")
    if cc_no_3==8:
        print("执行的是8张牌阵")
        for i in range(8):
            if i==0:
                img2 = cv2.imread(cc_no_4[i]) # 背景 仅仅第一次运行时
                img_2 = cv2.resize(img2, (638, 878))  # 改变背景的长宽 仅仅第一次运行时‘
                # cv2.imwrite("ceshi2.jpg", img_2)
            img1 = cv2.imread(cc_no_1[i])  # 读取卡片地址
            rows, cols = img1.shape[0:2]   #读取卡片的长宽
            img_1 = cv2.resize(img1, (int(cols / 2), int(rows / 2)))  # 改变卡片的长宽
            if cc_no_2[i]==1:
                img_1 = cv2.flip(img_1, -1)  # 但为逆位旋转180度
            cv2.imwrite("ceshi.jpg",img_1)
            img_1_1=img.open('ceshi.jpg')
            img_2_1 = img.open('ceshi2.jpg')
            cc_no=i+1
            if cc_no==1:
                a1_where=(160,140)
                img_2_1.paste(img_1_1,a1_where)
            elif cc_no==2:
                a2_where=(400,140)
                img_2_1.paste(img_1_1,a2_where)
            elif cc_no==3:
                a3_where=(279,20)
                img_2_1.paste(img_1_1,a3_where)
            elif cc_no==4:
                a4_where=(279,234)
                img_2_1.paste(img_1_1,a4_where)
            elif cc_no==5:
                a5_where=(160,448)
                img_2_1.paste(img_1_1,a5_where)
            elif cc_no == 6:
                a3_where = (400, 448)
                img_2_1.paste(img_1_1, a3_where)
            elif cc_no == 7:
                a4_where = (279, 448)
                img_2_1.paste(img_1_1, a4_where)
            elif cc_no == 8:
                a5_where = (279, 665)
                img_2_1.paste(img_1_1, a5_where)
            img_2_1.save("ceshi2.jpg")
    img._show(img_2_1)
    # os.remove('ceshi.jpg')
    img_2_1.save("输出结果结果%s.jpg"% \
                 name)
  • 结果的写入
def data_Write(gg,a1_1_type,mode,mima):
    db= pymysql.connect(host='localhost',
                                 user='root',
                                 password=mima,
                                 database='牌库数据')
    cursor = db.cursor()
    if mode==1:
        data_1 = input("请输入补充数据==")
        cc_1 = cursor.execute('UPDATE 牌分类牌意 SET %s = "%s" where 牌序号= %s' % \
                            (a1_1_type, data_1, gg))
        print("修改的数据条数= %s" % \
              cc_1)
        db.commit()
    if mode==2:
        jj=cursor.execute('select * from 牌分类牌意 where 牌序号= %s;'%\
                      gg )#gg输入id
    #返回查找到数据数目
        print("分类牌查询到的解释数据条数= %s"%\
              jj)
        db.commit()
        results = cursor.fetchall()
        try:
            for row in results:
                  id= row[0]
                  type1=row[1]
                  type2 = row[2]
                  type3=row[3]
                  type4 = row[4]
            ss_1 = ["学习"]
            ss_2 = ["工作"]
            ss_3 = ["爱情"]
            ss_4 = ["未来发展"]
            if a1_1_type in ss_1:
                print("学习类别下的解释:——————%s" % \
                      type1)
                pan_none(type1,gg,a1_1_type,)
            if a1_1_type in ss_2:
                print("工作类别下的解释:——————%s" % \
                      type2)
                pan_none(type2,gg,a1_1_type)
            if a1_1_type in ss_3:
                print("爱情类别下的解释:——————%s" % \
                      type3)
                pan_none(type3,gg,a1_1_type)
            if a1_1_type in ss_4:
                print("未来发展类别下的解释:——————%s" % \
                      type4)
                pan_none(type4,gg,a1_1_type)
            return id, type1, type2, type3, type4
        except:
            print("牌分类读取存在问题")
    db.close()
    # 关闭数据库连接

完整函数

# 版本0.1 2021年6月4日15点50分
# 1602480875@qq.com
# 尚帝 
import cv2
import numpy as np
import PIL.Image as img
import os,sys
import pymysql

# #输入执行信息
a1_1_name = 'name'
a1_1_sex = 1 # 分类标签 [1,2]
a1_1_type = '工作'  #工作 学习 爱情 未来发展
a1_1_type_1 = 'a'   # 分类标签 a b c d
a1_1_num = 3  # 牌阵数目 [3,5,8]
a1_1_weixie = '12345678'  # 微信号
a1_1_Divination_content = '我想知道我能当上逗逼王吗?'
a14_2 = ["bake.jpg"]  # 背景图片的地址
name ='最终测试' # 保存图片的名字
danhao = 1     # 问题储存记录
mima ='1602480875' # 密码
file_photo_dr = 'F:/软件安装包/项目文件/不更新/占卜/简化版/tupian/' # 卡图文件地址
# file_photo_dr = abspath(getsourcefile(lambda:0))
# print(file_photo_dr)

# 开始执行函数

# 输入数据保存
def data_Write_1(q_1, type_1, type_a, mode, mima):
    db= pymysql.connect(host='localhost', user='root', password=mima, database='牌库数据')
    cursor = db.cursor()
    if mode == 3:
        cc_1 = cursor.execute("INSERT INTO `牌库数据`.`数据原始问题集合`(`问题`, `分类`, `分类标签`) VALUES ('%s', '%s', '%s') " % \
                            (q_1,type_1,type_a))  # 写入数据
        if cc_1 == 1:
            print("成功保存问题数据 %s条" % \
                 cc_1)
    db.commit()
    db.close()
# 数据输入判断
def pan_duan_sex_data(a1_1_sex,a1_1_num):
    data_kongzhi_1=[1,2]
    data_kongzhi_2=[3,5,8]
    if a1_1_sex in data_kongzhi_1 :
        print("输入性别数据数据无错误")
    else:
         print("输入的性别数据存在问题,已经停止运行")
         sys.exit(0) #停止当前运行
    if a1_1_num in data_kongzhi_2 :
        print("输入牌阵数据数据无错误")
    else:
         print("输入的牌阵数据存在问题,已经停止运行")
         sys.exit(0) #停止当前运行
#分类数据录入函数
def pan_none(type,gg,a1_1_type):
    mode=1
    if type == None:
        print('--------------------------------------------------')
        print('是否需要补充此记录的数据')
        print('--------------------------------------------------')
        ax_1 = input("是否补充?1补充,2不补充=====")
        if int(ax_1) == 1:
            print('补充')
            data_Write(gg,a1_1_type,mode)
        else:
            print('不补充')
#数据分类读取程序
def data_Write(gg,a1_1_type,mode,mima):
    db= pymysql.connect(host='localhost',
                                 user='root',
                                 password=mima,
                                 database='牌库数据')
    cursor = db.cursor()
    if mode==1:
        data_1 = input("请输入补充数据==")
        cc_1 = cursor.execute('UPDATE 牌分类牌意 SET %s = "%s" where 牌序号= %s' % \
                            (a1_1_type, data_1, gg))
        print("修改的数据条数= %s" % \
              cc_1)
        db.commit()
    if mode==2:
        jj=cursor.execute('select * from 牌分类牌意 where 牌序号= %s;'%\
                      gg )#gg输入id
    #返回查找到数据数目
        print("分类牌查询到的解释数据条数= %s"%\
              jj)
        db.commit()
        results = cursor.fetchall()
        try:
            for row in results:
                  id= row[0]
                  type1=row[1]
                  type2 = row[2]
                  type3=row[3]
                  type4 = row[4]
            ss_1 = ["学习"]
            ss_2 = ["工作"]
            ss_3 = ["爱情"]
            ss_4 = ["未来发展"]
            if a1_1_type in ss_1:
                print("学习类别下的解释:——————%s" % \
                      type1)
                pan_none(type1,gg,a1_1_type,)
            if a1_1_type in ss_2:
                print("工作类别下的解释:——————%s" % \
                      type2)
                pan_none(type2,gg,a1_1_type)
            if a1_1_type in ss_3:
                print("爱情类别下的解释:——————%s" % \
                      type3)
                pan_none(type3,gg,a1_1_type)
            if a1_1_type in ss_4:
                print("未来发展类别下的解释:——————%s" % \
                      type4)
                pan_none(type4,gg,a1_1_type)
            return id, type1, type2, type3, type4
        except:
            print("牌分类读取存在问题")
    db.close()
    # 关闭数据库连接
#随机数产生函数
def rand_num(num_card):
    #num_card=input("请输入牌阵数目=")
    num_card=int(num_card)
    cx=np.zeros(int(num_card))
    cx_1=np.zeros(int(num_card))
    num_card_1=int(num_card)
    for i in range(num_card_1):
        cx[int(i)]=np.random.randint(1,156) #产生随机数
        while cx[i] in cx[1:i-1] and cx[i] in cx[1:i-1]-78:
            cx[int(i)] = np.random.randint(1, 156)
        if cx[int(i)]>78:
            cx_1[int(i)]=1
        else:
            cx_1[int(i)] =0
    print('产生的卡片序号分别是卡片=%s'%\
          cx)
    return cx_1,cx #产生随机数和结果

#牌库数据调用函数
def data_fetch(gg,mima):
    db= pymysql.connect(host='localhost',
                                 user='root',
                                 password=mima,
                                 database='牌库数据')
    cursor = db.cursor()
    jj=cursor.execute('select * from 牌直意库 where 牌序= %s;'%\
                      gg) #gg输入id
    # 使用 fetchone() 方法获取单条数据.
    #返回查找到数据数目
    # print("查询到的数据条数= %s"%\
    #       jj)
    db.commit()
    results = cursor.fetchall()
    try:
        for row in results:
              id= row[0]
              card_num= row[1]
              name = row[2]
              crad_way=row[3]
              mean_crad = row[4]
        return crad_way, mean_crad, name, id, card_num
        # print("id=%s,牌序=%s,牌名=%s,牌图地址=%s,牌图直接意思=%s" % \
              #(id,card_num,name,crad_way,mean_crad))
    except:
        print("读取存在问题")
    db.close()
    # 关闭数据库连接
#牌摆放函数
def crade_buzhi(cc_no_1,cc_no_2,cc_no_3,cc_no_4,name):
    if len(cc_no_1) != len(cc_no_2):
        print("输入的数据数目有误")
        os.system("pause")
    if cc_no_3 == 3:
        print("执行的是3张牌阵")
        for i in range(3):
            if i == 0:
                img2 = img.open(cc_no_4)
                # img2 = cv2.imread(cc_no_4[i])  # 背景 仅仅第一次运行时
                # img_2 = img2.resize(img2, (684, 589))  # 改变背景的长宽 仅仅第一次运行时‘
                img_2 = img2.resize((684, 589),img.ANTIALIAS)
                # img_2.save("ceshi2.jpg")
                # cv2.imwrite("ceshi2.jpg", img_2)
            img1 = img.open(cc_no_1[i])  # 读取卡片地址
            [rows, cols]= img1.size  # 读取卡片的长宽
            img_1 = img1.resize( (int(rows / 2), int(cols / 2)))  # 改变卡片的长宽
            if cc_no_2[i] == 1:
                img_1.transpose(img.ROTATE_180)
                # img_1 = cv2.flip(img_1, -1)  # 但为逆位旋转180度
            # cv2.imwrite("ceshi.jpg", img_1)
            # img_1_1 = img.open('ceshi.jpg')
            img_1_1 = img_1
            # img_2_1 = img.open('ceshi2.jpg')
            img_2_1 = img_2
            cc_no = i + 1
            if cc_no == 1:
                a1_where = (100, 200)
                img_2_1.paste(img_1_1, a1_where)
            elif cc_no == 2:
                a2_where = (260, 200)
                img_2_1.paste(img_1_1, a2_where)
            elif cc_no == 3:
                a3_where = (420, 200)
                img_2_1.paste(img_1_1, a3_where)

            img_2_1.save("ceshi2.jpg")
    if cc_no_3==5:
        print("执行的是5张牌阵")
        for i in range(5):
            if i==0:
                img2 = cv2.imread(cc_no_4[i]) # 背景 仅仅第一次运行时
                img_2 = cv2.resize(img2, (601, 733))  # 改变背景的长宽 仅仅第一次运行时‘
                cv2.imwrite("ceshi2.jpg", img_2)
            img1 = cv2.imread(cc_no_1[i])  # 读取卡片地址
            rows, cols = img1.shape[0:2]   #读取卡片的长宽
            img_1 = cv2.resize(img1, (int(cols / 2), int(rows / 2)))  # 改变卡片的长宽
            if cc_no_2[i]==1:
                img_1 = cv2.flip(img_1, -1)  # 但为逆位旋转180度
            cv2.imwrite("ceshi.jpg",img_1)
            img_1_1=img.open('ceshi.jpg')
            img_2_1 = img.open('ceshi2.jpg')
            cc_no=i+1
            if cc_no==3:
                a1_where=(120,50)
                img_2_1.paste(img_1_1,a1_where)
            elif cc_no == 5:
                a2_where = (371, 50)
                img_2_1.paste(img_1_1,a2_where)
            elif cc_no==2:
                a3_where=(177,280)
                img_2_1.paste(img_1_1,a3_where)
            elif cc_no==4:
                a4_where=(330,280)
                img_2_1.paste(img_1_1,a4_where)
            elif cc_no==1:
                a5_where=(248,506)
                img_2_1.paste(img_1_1,a5_where)
            img_2_1.save("ceshi2.jpg")
    if cc_no_3==8:
        print("执行的是8张牌阵")
        for i in range(8):
            if i==0:
                img2 = cv2.imread(cc_no_4[i]) # 背景 仅仅第一次运行时
                img_2 = cv2.resize(img2, (638, 878))  # 改变背景的长宽 仅仅第一次运行时‘
                # cv2.imwrite("ceshi2.jpg", img_2)
            img1 = cv2.imread(cc_no_1[i])  # 读取卡片地址
            rows, cols = img1.shape[0:2]   #读取卡片的长宽
            img_1 = cv2.resize(img1, (int(cols / 2), int(rows / 2)))  # 改变卡片的长宽
            if cc_no_2[i]==1:
                img_1 = cv2.flip(img_1, -1)  # 但为逆位旋转180度
            cv2.imwrite("ceshi.jpg",img_1)
            img_1_1=img.open('ceshi.jpg')
            img_2_1 = img.open('ceshi2.jpg')
            cc_no=i+1
            if cc_no==1:
                a1_where=(160,140)
                img_2_1.paste(img_1_1,a1_where)
            elif cc_no==2:
                a2_where=(400,140)
                img_2_1.paste(img_1_1,a2_where)
            elif cc_no==3:
                a3_where=(279,20)
                img_2_1.paste(img_1_1,a3_where)
            elif cc_no==4:
                a4_where=(279,234)
                img_2_1.paste(img_1_1,a4_where)
            elif cc_no==5:
                a5_where=(160,448)
                img_2_1.paste(img_1_1,a5_where)
            elif cc_no == 6:
                a3_where = (400, 448)
                img_2_1.paste(img_1_1, a3_where)
            elif cc_no == 7:
                a4_where = (279, 448)
                img_2_1.paste(img_1_1, a4_where)
            elif cc_no == 8:
                a5_where = (279, 665)
                img_2_1.paste(img_1_1, a5_where)
            img_2_1.save("ceshi2.jpg")
    img._show(img_2_1)
    # os.remove('ceshi.jpg')
    img_2_1.save("输出结果结果%s.jpg"% \
                 name)
    return
def file_name(file_dir):
    for root,dirs,files in os.walk(file_dir):
        # print('目录路径    :',root)
        # print('子目录名称  :',dirs)
        # print('目录下的文件:',files)
        # print("\n")

        return files, root



#运行函数
if __name__ == '__main__':
    pan_duan_sex_data(a1_1_sex,a1_1_num)
    [a11_1,b11_1]=rand_num(a1_1_num) #返回翻转矩阵和随机数矩阵
    a13_1=[]
    a13_2=[]
    a13_3=[]
    for i in b11_1:
        # [a12_1,a12_2,a12_3,a12_4,a12_5]=data_fetch(i, mima) #利用数据库读取
        ptos_flies, root_name = file_name(file_photo_dr)
        num_x = ptos_flies.__len__()
        ax_name = list(range(num_x))
        ptos_flies.sort();
        for j in range(num_x-1):
            ax_name[j] = root_name + ptos_flies[j]
        # print(ax_name)
        if (i<=75):
            a12_1=ax_name[int(i)]
        else:
            a12_1 = ax_name[int(i/2)]
        a12_2='测试成功'
        a12_3='高贵的1'
        a13_1.append(a12_1) #卡图地址
        a13_2.append(a12_2) #牌的直接意思
        a13_3.append(a12_3) #卡片名称
    # print("查找到的卡图地址%s"%\
    #       a13_1)
    print("查找到的直接牌意%s"%\
          a13_2)
    print("查找到的牌名%s"%\
          a13_3)
    # 牌阵类型
    a14_1 = len(a13_1)
    #读取分类下的每张牌的解释
    for i in b11_1:
       # data_Write(i, a1_1_type,2,mima)
       a14_2=('bake.jpg')
    #调用函数 牌地址 反转矩阵 牌阵类型 背景的地址 图片保存名字
    crade_buzhi(a13_1, a11_1, a14_1, a14_2,name)

    a15_1=input('是否保留本次运行的结果1保存,2不保存===')
    if int(a15_1)==1:
        print('保存')
        print('这功能没法用了')
        # data_Write_1(a1_1_Divination_content, a1_1_type,a1_1_type_1, 3,mima)  # 问题序号 问题内容 问题分类 问题分类标签

    else:
        print('不保存')

运行需要的组件

在这里插入图片描述

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值