Python tkinker 界面设计与图标设置和图片文件打包成单个exe

这篇具有很好参考价值的文章主要介绍了Python tkinker 界面设计与图标设置和图片文件打包成单个exe。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1.  python 打包图片资源文件和逻辑文件,以及桌面应用图标

pyinstaller -F ae_awb_tool.py  -p png_resource.py -i 1.ico -w

 2. 完整代码如下。其作用是调用MTK 研发的图片信息dump工具,对图片AE 和AWB 进行分析归类到所属的目录中,并统计目录下文件个数,填充到最后一级文件夹名称开头。

3. 将图片文件转换为 py文件的脚本


import base64
import tkinter.messagebox as msgbox
def picture_to_py(pic_name):
    convert_pic_past = open("%s" % pic_name, 'rb')  # 这里传入要转换的图片
    base64_convert_str = base64.b64encode(convert_pic_past.read())  # base64读取(字符串)
    convert_pic_past.close() # 关闭读取
    convert_write_data = 'img = "%s"' % base64_convert_str.decode() # 处理
    a = open('%s.py' % pic_name.replace('.', '_'), 'w+')
    a.write(convert_write_data)
    a.close()
 
if __name__ == '__main__':
    picture = ["PCBico.png"]  # 写入你要转换的文件名,建议把该代码保存到与转换图片相同路径下
    for x in picture:
        picture_to_py(x)
    msgbox.showinfo("tip", "convert successfully.")
————————————————
版权声明:本文为CSDN博主「lagesan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lagesan/article/details/128415788

4. 主逻辑脚本内容如下: 

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os,base64
from tkinter.messagebox import showinfo
import matplotlib.pyplot as plt
import numpy as np
import subprocess
import datetime
import re
from png_resource import img as img_pic
import tkinter as tk
from tkinter import filedialog

import shutil

starttime = datetime.datetime.now()

global debug_Tool
global photopath
def select_tool_dir():
    global debug_Tool
    debug_entry.set("")
    debug_Tool = filedialog.askopenfile(initialdir=os.getcwd()).name
    if debug_Tool.endswith("DebugParser.exe"):
        debug_entry.set(debug_Tool)
    if os.path.exists(os.getcwd()+"\default_path.txt")  == False:
        with open(os.getcwd() + "\default_path.txt", 'w+') as f_default_path:
            f_default_path.close()
    with open(os.getcwd()+"\default_path.txt", 'r+') as f_default_path:
        lines = f_default_path.readlines()
        file_contents = []
        for line in lines:
            if line.startswith("tool_deault_dir=") == False:
                file_contents.append(line)
        f_default_path.seek(0)
        for content in file_contents:
            f_default_path.write(content)
        path_str = "tool_deault_dir=" + debug_Tool+'\n'
        f_default_path.write(path_str)
        f_default_path.close()

def select_picture_path():
    global photopath
    photo_entry.set("")
    photopath = filedialog.askdirectory(initialdir=os.getcwd())  # 使用askdirectory函数选择文件夹
    photopath += "/"
    photo_entry.set(photopath)

    if os.path.exists(os.getcwd()+"\default_path.txt")  == False:
        with open(os.getcwd() + "\default_path.txt", 'w+') as f_default_path:
            f_default_path.close()
    with open(os.getcwd() + "\default_path.txt", 'r+') as f_default_path:
        lines = f_default_path.readlines()
        file_contents = []
        for line in lines:
            if line.startswith("photo_deault_dir=") == False:
                file_contents.append(line)
        f_default_path.seek(0)
        for content in file_contents:
            f_default_path.write(content)
        path_str = "photo_deault_dir=" + photopath+'\n'
        f_default_path.write(path_str)
        f_default_path.close()



def analyse(exifpath):
    data = {
        "name": str,
        "AE_TAG_REALBVX1000": str,
        "AE_TAG_HS_EVD": str,
        "AE_TAG_FACE_STS_SIZE": str,
        "AE_TAG_FLT_DR": str,
        "AE_TAG_FLT_FDY": str
    }

    AE_TAG_REALBVX1000 = []
    AE_TAG_HS_EVD = []
    AE_TAG_FACE_STS_SIZE = []
    AE_TAG_FLT_DR = []
    AE_TAG_REALBVX1000_Normal = []
    AE_TAG_HS_EVD_Normal = []
    # exif 目录

    result = {
        # 无人脸
        "bv -∞~-1500 & evd -∞~1000": [0, []],
        "bv -∞~-1500 & evd 1000~4200": [0, []],
        "bv -∞~-1500 & evd 4200~6300": [0, []],
        "bv -∞~-1500 & evd 6300+": [0, []],

        "bv -1500~500 & evd -∞~1000": [0, []],
        "bv -1500~500 & evd 1000~4200": [0, []],
        "bv -1500~500 & evd 4200~6300": [0, []],
        "bv -1500~500 & evd 6300+": [0, []],

        "bv 500~2500 & evd -∞~1000": [0, []],
        "bv 500~2500 & evd 1000~4200": [0, []],
        "bv 500~2500 & evd 4200~6300": [0, []],
        "bv 500~2500 & evd 6300+": [0, []],

        "bv 2500~5000 & evd -∞~1000": [0, []],
        "bv 2500~5000 & evd 1000~4200": [0, []],
        "bv 2500~5000 & evd 4200~6300": [0, []],
        "bv 2500~5000 & evd 6300+": [0, []],

        "bv 5000~8000 & evd -∞~1000": [0, []],
        "bv 5000~8000 & evd 1000~4200": [0, []],
        "bv 5000~8000 & evd 4200~6300": [0, []],
        "bv 5000~8000 & evd 6300+": [0, []],

        "bv 8000~10000 & evd -∞~1000": [0, []],
        "bv 8000~10000 & evd 1000~4200": [0, []],
        "bv 8000~10000 & evd 4200~6300": [0, []],
        "bv 8000~10000 & evd 6300+": [0, []],

        "bv 10000+ & evd -∞~1000": [0, []],
        "bv 10000+ & evd 1000~4200": [0, []],
        "bv 10000+ & evd 4200~6300": [0, []],
        "bv 10000+ & evd 6300+": [0, []],

        # 人脸
        "bv -∞~-2000 & fdr -∞~0": [0, []],
        "bv -∞~-2000 & fdr 0~1800": [0, []],
        "bv -∞~-2000 & fdr 1800~2800": [0, []],
        "bv -∞~-2000 & fdr 2800~4000": [0, []],
        "bv -∞~-2000 & fdr 4000+": [0, []],

        "bv -2000~0 & fdr -∞~0": [0, []],
        "bv -2000~0 & fdr 0~1800": [0, []],
        "bv -2000~0 & fdr 1800~2800": [0, []],
        "bv -2000~0 & fdr 2800~4000": [0, []],
        "bv -2000~0 & fdr 4000+": [0, []],

        "bv 0~3000 & fdr -∞~0": [0, []],
        "bv 0~3000 & fdr 0~1800": [0, []],
        "bv 0~3000 & fdr 1800~2800": [0, []],
        "bv 0~3000 & fdr 2800~4000": [0, []],
        "bv 0~3000 & fdr 4000+": [0, []],

        "bv 3000~6000 & fdr -∞~0": [0, []],
        "bv 3000~6000 & fdr 0~1800": [0, []],
        "bv 3000~6000 & fdr 1800~2800": [0, []],
        "bv 3000~6000 & fdr 2800~4000": [0, []],
        "bv 3000~6000 & fdr 4000+": [0, []],

        "bv 6000~8500 & fdr -∞~0": [0, []],
        "bv 6000~8500 & fdr 0~1800": [0, []],
        "bv 6000~8500 & fdr 1800~2800": [0, []],
        "bv 6000~8500 & fdr 2800~4000": [0, []],
        "bv 6000~8500 & fdr 4000+": [0, []],

        "bv 8500+ & fdr -∞~0": [0, []],
        "bv 8500+ & fdr 0~1800": [0, []],
        "bv 8500+ & fdr 1800~2800": [0, []],
        "bv 8500+ & fdr 2800~4000": [0, []],
        "bv 8500+ & fdr 4000+": [0, []],

    }

    with open(exifpath + "SearchResult.exif", 'r') as ef:
        lines = ef.readlines()
    count = 0
    # 拿到每一个exif中需要的信息 放在data中

    for line in lines:

        count += 1
        # 取每一张图片的信息 放在data中
        if count % 8 != 0:
            if ".jpg" in line:
                data["name"] = re.findall(r"[\[](.*?)[\]]", line)[0]
                name = photopath.split("/")[-2]
            elif line != "\n":
                dataname = line.split(":")[0].replace(" ", "")
                value = line.split(":")[1].replace(" ", "").replace("\n", "")
                data[dataname] = value
        else:
            # 判断每个exif的区域信息
            if int(data["AE_TAG_FACE_STS_SIZE"]) > 13 and int(data["AE_TAG_FLT_FDY"]) != 0:
                if 0 > int(data['AE_TAG_FLT_DR']) and -2000 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-2000 & fdr -∞~0'][0] += 1
                    result['bv -∞~-2000 & fdr -∞~0'][1].append(data["name"])
                if 1800 > int(data['AE_TAG_FLT_DR']) >= 0 and -2000 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-2000 & fdr 0~1800'][0] += 1
                    result['bv -∞~-2000 & fdr 0~1800'][1].append(data["name"])
                if 2800 > int(data['AE_TAG_FLT_DR']) >= 1800 and -2000 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-2000 & fdr 1800~2800'][0] += 1
                    result['bv -∞~-2000 & fdr 1800~2800'][1].append(data["name"])
                if 4000 > int(data['AE_TAG_FLT_DR']) >= 2800 and -2000 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-2000 & fdr 2800~4000'][0] += 1
                    result['bv -∞~-2000 & fdr 2800~4000'][1].append(data["name"])
                if int(data['AE_TAG_FLT_DR']) >= 4000 and -2000 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-2000 & fdr 4000+'][0] += 1
                    result['bv -∞~-2000 & fdr 4000+'][1].append(data["name"])

                if 0 > int(data['AE_TAG_FLT_DR']) and 0 > int(data['AE_TAG_REALBVX1000']) >= -2000:
                    result['bv -2000~0 & fdr -∞~0'][0] += 1
                    result['bv -2000~0 & fdr -∞~0'][1].append(data["name"])
                if 1800 > int(data['AE_TAG_FLT_DR']) >= 0 and 0 > int(data['AE_TAG_REALBVX1000']) >= -2000:
                    result['bv -2000~0 & fdr 0~1800'][0] += 1
                    result['bv -2000~0 & fdr 0~1800'][1].append(data["name"])
                if 2800 > int(data['AE_TAG_FLT_DR']) >= 1800 and 0 > int(data['AE_TAG_REALBVX1000']) >= -2000:
                    result['bv -2000~0 & fdr 1800~2800'][0] += 1
                    result['bv -2000~0 & fdr 1800~2800'][1].append(data["name"])
                if 4000 > int(data['AE_TAG_FLT_DR']) >= 2800 and 0 > int(data['AE_TAG_REALBVX1000']) >= -2000:
                    result['bv -2000~0 & fdr 2800~4000'][0] += 1
                    result['bv -2000~0 & fdr 2800~4000'][1].append(data["name"])
                if int(data['AE_TAG_FLT_DR']) >= 4000 and 0 > int(data['AE_TAG_REALBVX1000']) >= -2000:
                    result['bv -2000~0 & fdr 4000+'][0] += 1
                    result['bv -2000~0 & fdr 4000+'][1].append(data["name"])

                if 0 > int(data['AE_TAG_FLT_DR']) and 3000 > int(data['AE_TAG_REALBVX1000']) >= 0:
                    result['bv 0~3000 & fdr -∞~0'][0] += 1
                    result['bv 0~3000 & fdr -∞~0'][1].append(data["name"])
                if 1800 > int(data['AE_TAG_FLT_DR']) >= 0 and 3000 > int(data['AE_TAG_REALBVX1000']) >= 0:
                    result['bv 0~3000 & fdr 0~1800'][0] += 1
                    result['bv 0~3000 & fdr 0~1800'][1].append(data["name"])
                if 2800 > int(data['AE_TAG_FLT_DR']) >= 1800 and 3000 > int(data['AE_TAG_REALBVX1000']) >= 0:
                    result['bv 0~3000 & fdr 1800~2800'][0] += 1
                    result['bv 0~3000 & fdr 1800~2800'][1].append(data["name"])
                if 4000 > int(data['AE_TAG_FLT_DR']) >= 2800 and 3000 > int(data['AE_TAG_REALBVX1000']) >= 0:
                    result['bv 0~3000 & fdr 2800~4000'][0] += 1
                    result['bv 0~3000 & fdr 2800~4000'][1].append(data["name"])
                if int(data['AE_TAG_FLT_DR']) >= 4000 and 3000 > int(data['AE_TAG_REALBVX1000']) >= 0:
                    result['bv 0~3000 & fdr 4000+'][0] += 1
                    result['bv 0~3000 & fdr 4000+'][1].append(data["name"])

                if 0 > int(data['AE_TAG_FLT_DR']) and 6000 > int(data['AE_TAG_REALBVX1000']) >= 3000:
                    result['bv 3000~6000 & fdr -∞~0'][0] += 1
                    result['bv 3000~6000 & fdr -∞~0'][1].append(data["name"])
                if 1800 > int(data['AE_TAG_FLT_DR']) >= 0 and 6000 > int(data['AE_TAG_REALBVX1000']) >= 3000:
                    result['bv 3000~6000 & fdr 0~1800'][0] += 1
                    result['bv 3000~6000 & fdr 0~1800'][1].append(data["name"])
                if 2800 > int(data['AE_TAG_FLT_DR']) >= 1800 and 6000 > int(data['AE_TAG_REALBVX1000']) >= 3000:
                    result['bv 3000~6000 & fdr 1800~2800'][0] += 1
                    result['bv 3000~6000 & fdr 1800~2800'][1].append(data["name"])
                if 4000 > int(data['AE_TAG_FLT_DR']) >= 2800 and 6000 > int(data['AE_TAG_REALBVX1000']) >= 3000:
                    result['bv 3000~6000 & fdr 2800~4000'][0] += 1
                    result['bv 3000~6000 & fdr 2800~4000'][1].append(data["name"])
                if int(data['AE_TAG_FLT_DR']) >= 4000 and 6000 > int(data['AE_TAG_REALBVX1000']) >= 3000:
                    result['bv 3000~6000 & fdr 4000+'][0] += 1
                    result['bv 3000~6000 & fdr 4000+'][1].append(data["name"])

                if 0 > int(data['AE_TAG_FLT_DR']) and 8500 > int(data['AE_TAG_REALBVX1000']) >= 6000:
                    result['bv 6000~8500 & fdr -∞~0'][0] += 1
                    result['bv 6000~8500 & fdr -∞~0'][1].append(data["name"])
                if 1800 > int(data['AE_TAG_FLT_DR']) >= 0 and 8500 > int(data['AE_TAG_REALBVX1000']) >= 6000:
                    result['bv 6000~8500 & fdr 0~1800'][0] += 1
                    result['bv 6000~8500 & fdr 0~1800'][1].append(data["name"])
                if 2800 > int(data['AE_TAG_FLT_DR']) >= 1800 and 8500 > int(data['AE_TAG_REALBVX1000']) >= 6000:
                    result['bv 6000~8500 & fdr 1800~2800'][0] += 1
                    result['bv 6000~8500 & fdr 1800~2800'][1].append(data["name"])
                if 4000 > int(data['AE_TAG_FLT_DR']) >= 2800 and 8500 > int(data['AE_TAG_REALBVX1000']) >= 6000:
                    result['bv 6000~8500 & fdr 2800~4000'][0] += 1
                    result['bv 6000~8500 & fdr 2800~4000'][1].append(data["name"])
                if int(data['AE_TAG_FLT_DR']) >= 4000 and 8500 > int(data['AE_TAG_REALBVX1000']) >= 6000:
                    result['bv 6000~8500 & fdr 4000+'][0] += 1
                    result['bv 6000~8500 & fdr 4000+'][1].append(data["name"])

                if 0 > int(data['AE_TAG_FLT_DR']) and int(data['AE_TAG_REALBVX1000']) >= 8500:
                    result['bv 8500+ & fdr -∞~0'][0] += 1
                    result['bv 8500+ & fdr -∞~0'][1].append(data["name"])
                if 1800 > int(data['AE_TAG_FLT_DR']) >= 0 and int(data['AE_TAG_REALBVX1000']) >= 8500:
                    result['bv 8500+ & fdr 0~1800'][0] += 1
                    result['bv 8500+ & fdr 0~1800'][1].append(data["name"])
                if 2800 > int(data['AE_TAG_FLT_DR']) >= 1800 and int(data['AE_TAG_REALBVX1000']) >= 8500:
                    result['bv 8500+ & fdr 1800~2800'][0] += 1
                    result['bv 8500+ & fdr 1800~2800'][1].append(data["name"])
                if 4000 > int(data['AE_TAG_FLT_DR']) >= 2800 and int(data['AE_TAG_REALBVX1000']) >= 8500:
                    result['bv 8500+ & fdr 2800~4000'][0] += 1
                    result['bv 8500+ & fdr 2800~4000'][1].append(data["name"])
                if int(data['AE_TAG_FLT_DR']) >= 4000 and int(data['AE_TAG_REALBVX1000']) >= 8500:
                    result['bv 8500+ & fdr 4000+'][0] += 1
                    result['bv 8500+ & fdr 4000+'][1].append(data["name"])

            else:
                if 1000 > int(data['AE_TAG_HS_EVD']) and -1500 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-1500 & evd -∞~1000'][0] += 1
                    result['bv -∞~-1500 & evd -∞~1000'][1].append(data["name"])
                if 4200 > int(data['AE_TAG_HS_EVD']) >= 1000 and -1500 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-1500 & evd 1000~4200'][0] += 1
                    result['bv -∞~-1500 & evd 1000~4200'][1].append(data["name"])
                if 6300 > int(data['AE_TAG_HS_EVD']) >= 4200 and -1500 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-1500 & evd 4200~6300'][0] += 1
                    result['bv -∞~-1500 & evd 4200~6300'][1].append(data["name"])
                if int(data['AE_TAG_HS_EVD']) >= 6300 and -1500 > int(data['AE_TAG_REALBVX1000']):
                    result['bv -∞~-1500 & evd 6300+'][0] += 1
                    result['bv -∞~-1500 & evd 6300+'][1].append(data["name"])

                if 1000 > int(data['AE_TAG_HS_EVD']) and 500 > int(data['AE_TAG_REALBVX1000']) >= -1500:
                    result['bv -1500~500 & evd -∞~1000'][0] += 1
                    result['bv -1500~500 & evd -∞~1000'][1].append(data["name"])
                if 4200 > int(data['AE_TAG_HS_EVD']) >= 1000 and 500 > int(data['AE_TAG_REALBVX1000']) >= -1500:
                    result['bv -1500~500 & evd 1000~4200'][0] += 1
                    result['bv -1500~500 & evd 1000~4200'][1].append(data["name"])
                if 6300 > int(data['AE_TAG_HS_EVD']) >= 4200 and 500 > int(data['AE_TAG_REALBVX1000']) >= -1500:
                    result['bv -1500~500 & evd 4200~6300'][0] += 1
                    result['bv -1500~500 & evd 4200~6300'][1].append(data["name"])
                if int(data['AE_TAG_HS_EVD']) >= 6300 and 500 > int(data['AE_TAG_REALBVX1000']) >= -1500:
                    result['bv -1500~500 & evd 6300+'][0] += 1
                    result['bv -1500~500 & evd 6300+'][1].append(data["name"])

                if 1000 > int(data['AE_TAG_HS_EVD']) and 2500 > int(data['AE_TAG_REALBVX1000']) >= 500:
                    result['bv 500~2500 & evd -∞~1000'][0] += 1
                    result['bv 500~2500 & evd -∞~1000'][1].append(data["name"])
                if 4200 > int(data['AE_TAG_HS_EVD']) >= 1000 and 2500 > int(data['AE_TAG_REALBVX1000']) >= 500:
                    result['bv 500~2500 & evd 1000~4200'][0] += 1
                    result['bv 500~2500 & evd 1000~4200'][1].append(data["name"])
                if 6300 > int(data['AE_TAG_HS_EVD']) >= 4200 and 2500 > int(data['AE_TAG_REALBVX1000']) >= 500:
                    result['bv 500~2500 & evd 4200~6300'][0] += 1
                    result['bv 500~2500 & evd 4200~6300'][1].append(data["name"])
                if int(data['AE_TAG_HS_EVD']) >= 6300 and 2500 > int(data['AE_TAG_REALBVX1000']) >= 500:
                    result['bv 500~2500 & evd 6300+'][0] += 1
                    result['bv 500~2500 & evd 6300+'][1].append(data["name"])

                if 1000 > int(data['AE_TAG_HS_EVD']) and 5000 > int(data['AE_TAG_REALBVX1000']) >= 2500:
                    result['bv 2500~5000 & evd -∞~1000'][0] += 1
                    result['bv 2500~5000 & evd -∞~1000'][1].append(data["name"])
                if 4200 > int(data['AE_TAG_HS_EVD']) >= 1000 and 5000 > int(data['AE_TAG_REALBVX1000']) >= 2500:
                    result['bv 2500~5000 & evd 1000~4200'][0] += 1
                    result['bv 2500~5000 & evd 1000~4200'][1].append(data["name"])
                if 6300 > int(data['AE_TAG_HS_EVD']) >= 4200 and 5000 > int(data['AE_TAG_REALBVX1000']) >= 2500:
                    result['bv 2500~5000 & evd 4200~6300'][0] += 1
                    result['bv 2500~5000 & evd 4200~6300'][1].append(data["name"])
                if int(data['AE_TAG_HS_EVD']) >= 6300 and 5000 > int(data['AE_TAG_REALBVX1000']) >= 2500:
                    result['bv 2500~5000 & evd 6300+'][0] += 1
                    result['bv 2500~5000 & evd 6300+'][1].append(data["name"])

                if 1000 > int(data['AE_TAG_HS_EVD']) and 8000 > int(data['AE_TAG_REALBVX1000']) >= 5000:
                    result['bv 5000~8000 & evd -∞~1000'][0] += 1
                    result['bv 5000~8000 & evd -∞~1000'][1].append(data["name"])
                if 4200 > int(data['AE_TAG_HS_EVD']) >= 1000 and 8000 > int(data['AE_TAG_REALBVX1000']) >= 5000:
                    result['bv 5000~8000 & evd 1000~4200'][0] += 1
                    result['bv 5000~8000 & evd 1000~4200'][1].append(data["name"])
                if 6300 > int(data['AE_TAG_HS_EVD']) >= 4200 and 8000 > int(data['AE_TAG_REALBVX1000']) >= 5000:
                    result['bv 5000~8000 & evd 4200~6300'][0] += 1
                    result['bv 5000~8000 & evd 4200~6300'][1].append(data["name"])
                if int(data['AE_TAG_HS_EVD']) >= 6300 and 8000 > int(data['AE_TAG_REALBVX1000']) >= 5000:
                    result['bv 5000~8000 & evd 6300+'][0] += 1
                    result['bv 5000~8000 & evd 6300+'][1].append(data["name"])

                if 1000 > int(data['AE_TAG_HS_EVD']) and 10000 > int(data['AE_TAG_REALBVX1000']) >= 8000:
                    result['bv 8000~10000 & evd -∞~1000'][0] += 1
                    result['bv 8000~10000 & evd -∞~1000'][1].append(data["name"])
                if 4200 > int(data['AE_TAG_HS_EVD']) >= 1000 and 10000 > int(data['AE_TAG_REALBVX1000']) >= 8000:
                    result['bv 8000~10000 & evd 1000~4200'][0] += 1
                    result['bv 8000~10000 & evd 1000~4200'][1].append(data["name"])
                if 6300 > int(data['AE_TAG_HS_EVD']) >= 4200 and 10000 > int(data['AE_TAG_REALBVX1000']) >= 8000:
                    result['bv 8000~10000 & evd 4200~6300'][0] += 1
                    result['bv 8000~10000 & evd 4200~6300'][1].append(data["name"])
                if int(data['AE_TAG_HS_EVD']) >= 6300 and 10000 > int(data['AE_TAG_REALBVX1000']) >= 8000:
                    result['bv 8000~10000 & evd 6300+'][0] += 1
                    result['bv 8000~10000 & evd 6300+'][1].append(data["name"])

                if 1000 > int(data['AE_TAG_HS_EVD']) and int(data['AE_TAG_REALBVX1000']) >= 10000:
                    result['bv 10000+ & evd -∞~1000'][0] += 1
                    result['bv 10000+ & evd -∞~1000'][1].append(data["name"])
                if 4200 > int(data['AE_TAG_HS_EVD']) >= 1000 and int(data['AE_TAG_REALBVX1000']) >= 10000:
                    result['bv 10000+ & evd 1000~4200'][0] += 1
                    result['bv 10000+ & evd 1000~4200'][1].append(data["name"])
                if 6300 > int(data['AE_TAG_HS_EVD']) >= 4200 and int(data['AE_TAG_REALBVX1000']) >= 10000:
                    result['bv 10000+ & evd 4200~6300'][0] += 1
                    result['bv 10000+ & evd 4200~6300'][1].append(data["name"])
                if int(data['AE_TAG_HS_EVD']) >= 6300 and int(data['AE_TAG_REALBVX1000']) >= 10000:
                    result['bv 10000+ & evd 6300+'][0] += 1
                    result['bv 10000+ & evd 6300+'][1].append(data["name"])

            # 把这一个exif放数组中
            if int(data['AE_TAG_FACE_STS_SIZE']) > 13 and int(data["AE_TAG_FLT_FDY"]) != 0:
                AE_TAG_REALBVX1000.append(data['AE_TAG_REALBVX1000'])
                AE_TAG_FLT_DR.append(data['AE_TAG_FLT_DR'])
            else:
                AE_TAG_REALBVX1000_Normal.append(data['AE_TAG_REALBVX1000'])
                AE_TAG_HS_EVD_Normal.append(data['AE_TAG_HS_EVD'])



    return result, name, AE_TAG_HS_EVD_Normal, AE_TAG_REALBVX1000_Normal, AE_TAG_REALBVX1000,AE_TAG_FLT_DR,


def run_AE():
    global photopath
    result_CCT = [ "CCT  -∞  ~  2300", "CCT =2300 ~ 2850", "CCT =2850 ~ 3750",
                   "CCT =3750 ~ 5100", "CCT =5100 ~ 6500", "CCT =6500 ~   ∞"]
    for cct_key in result_CCT:
        dir_name = photopath + "\\" + cct_key
        if os.path.isdir(dir_name):
            shutil.rmtree(dir_name)
    result_AE=["Face","Normal"]
    for cct_key in result_AE:
        dir_name = photopath + "\\" + cct_key
        if os.path.isdir(dir_name):
            shutil.rmtree(dir_name)
    # child = subprocess.Popen(f"{debug} -dump {photopath}  -find \"AE_TAG_HS_EVD|AE_TAG_REALBVX1000|AE_TAG_FACE_STS_SIZE|AE_TAG_FLT_DR\" -save {photopath}/exif/")
    child1 = subprocess.Popen(
        f"{debug_Tool} -dump {photopath} -find \"AE_TAG_HS_EVD|AE_TAG_REALBVX1000|AE_TAG_FACE_STS_SIZE|AE_TAG_FLT_DR|AE_TAG_FLT_FDY\" -save {photopath}/")

    child1.wait()

    result,name, AE_TAG_HS_EVD_Normal, AE_TAG_REALBVX1000_Normal, AE_TAG_REALBVX1000,AE_TAG_FLT_DR, = analyse(photopath)


    os.mkdir(photopath + "Face")
    os.mkdir(photopath + "Normal")

    for dirname in result:
        if not os.path.exists(str(result[dirname][0]) + "  " + dirname.replace(" ", " ")):
            os.mkdir(photopath + str(result[dirname][0]) + "  " + dirname.replace(" ", " "))

    for photoname in os.listdir(photopath):
        for dirname in result:
            if photoname in result[dirname][1]:
                shutil.copyfile(photopath + photoname,
                                photopath + str(result[dirname][0]) + "  " + dirname.replace(" ",
                                                                                             " ") + f"/{photoname}")

    # 帮助跳出外层循环
    switchflag = True
    for dirpath, dirnames, filenames in os.walk(photopath):
        if switchflag:
            break
    for dirname in dirnames:
        if dirname == "Face" or dirname == "Normal":
            switchflag = False
            break
        if "evd" in dirname:
            shutil.move(photopath + dirname, photopath + "Normal")
        if "fdr" in dirname:
            shutil.move(photopath + dirname, photopath + "Face")

    x = len(AE_TAG_FLT_DR)
    y = len(AE_TAG_HS_EVD_Normal)
    result1 = '{:.2%}'.format(x / (x + y))
    result2 = '{:.2%}'.format(y / (x + y))

    ##绘制Normal散点图表
    x_bv = np.asarray(AE_TAG_REALBVX1000_Normal, dtype=int)
    y_evd = np.asarray(AE_TAG_HS_EVD_Normal, dtype=int)


    my_x_ticks = [-1500, 500, 2500, 5000, 8000, 10000]
    my_y_ticks = [0, 1000, 4200, 6300]
    plt.xlim(-8000, 15000)
    plt.ylim(-5000, 10000)
    plt.xticks(ticks=my_x_ticks)
    plt.yticks(ticks=my_y_ticks)
    # 设置图表标题并给坐标轴加上标签
    plt.title(f'{name} Normal:{y}/{x + y}  {result2}', fontsize=24)
    plt.xlabel('AE_TAG_REALBVX1000', fontsize=14)
    plt.ylabel('AE_TAG_HS_EVD', fontsize=14)
    plt.scatter(x_bv, y_evd, s=30,label="pic")

    plt.legend()
    plt.savefig(f'{photopath}Normal/result_Normal.png', dpi=300)
    plt.close()


    ##绘制Face散点图
    x_bv = np.asarray(AE_TAG_REALBVX1000, dtype=int)
    y_dr = np.asarray(AE_TAG_FLT_DR, dtype=int)

    my_x_ticks = [-2000, 0, 3000, 6000, 8500]
    my_y_ticks = [0, 1800, 2800, 4000]
    plt.xlim(-8000, 15000)
    plt.ylim(-2000, 8000)
    plt.xticks(my_x_ticks)
    plt.yticks(my_y_ticks)
    # 设置图表标题并给坐标轴加上标签

    plt.title(f'{name} Face:{x}/{x + y}  {result1}', fontsize=24)
    plt.xlabel('AE_TAG_REALBVX1000', fontsize=14)
    plt.ylabel('AE_TAG_FLT_DR', fontsize=14)
    plt.scatter(x_bv, y_dr, s=20, label="pic")

    plt.legend()
    plt.savefig(f'{photopath}Face/result_Face.png', dpi=300)
    plt.close()
    endtime = datetime.datetime.now()

    showinfo(title='提示', message='AE分类 操作成功!')

class result_LV_obj:
    def __init__(self):
        self.result_LV = {
            "LV  -∞  ~  0" : 0,
            'LV =0 ~ 20'   : 0,
            'LV =20 ~ 40'  : 0,
            'LV =40 ~ 60'  : 0,
            'LV =60 ~ 80'  : 0,
            'LV =80 ~ 100' : 0,
            'LV =100 ~ 120': 0,
            'LV =120 ~ 140': 0,
            'LV =140 ~ 160': 0,
            'LV =160 ~ 180': 0,
        }

def analyse_AWB(exifpath,result_CCT):
    with open(exifpath + "\SearchResult.exif", 'r', encoding='utf-8') as ef:
        lines = ef.readlines()

    cur_file_name = ''
    cur_file_path = ''
    cur_CCT_key = ''
    cur_LV_key = ''
    for line in lines:
        cur_line_is_CCT = 0
        cur_line_is_LV = 0
        if ".jpg" in line:
            cur_file_path = exifpath + '\\'
            cur_file_name = re.findall(r"[\[](.*?)[\]]", line)[0]
            cur_CCT_key = ''
            cur_LV_key = ''
            continue
        elif line != "\n":
            data_name = line.split(":")[0].replace(" ", "")
            data_value = line.split(":")[1].replace(" ", "").replace("\n", "")
            if data_name == 'AWB_TAG_CCT':
                cur_line_is_CCT = 1
            elif data_name == 'AWB_TAG_ALGO_SCENE_LV':
                cur_line_is_LV = 1
            else:
                continue
        if cur_line_is_CCT == 1:
            cur_CCT = int(data_value)
            if cur_CCT < 2300:
                cur_CCT_key = 'CCT  -∞  ~  2300'
            elif cur_CCT < 2850:
                cur_CCT_key = 'CCT =2300 ~ 2850'
            elif cur_CCT < 3750:
                cur_CCT_key = 'CCT =2850 ~ 3750'
            elif cur_CCT < 5100:
                cur_CCT_key = 'CCT =3750 ~ 5100'
            elif cur_CCT < 6500:
                cur_CCT_key = 'CCT =5100 ~ 6500'
            else:
                cur_CCT_key = 'CCT =6500 ~   ∞'
            if cur_LV_key != '':
                if not os.path.exists(cur_file_path+ cur_CCT_key + "/" + cur_LV_key):
                    if not os.path.exists(cur_file_path+ cur_CCT_key):
                        os.mkdir(cur_file_path+ cur_CCT_key )
                    os.mkdir(cur_file_path + cur_CCT_key + "/" + cur_LV_key)
                result_CCT[cur_CCT_key].result_LV[cur_LV_key] += 1
                src_path = cur_file_path + cur_file_name
                dst_path = cur_file_path + cur_CCT_key + "\\" + cur_LV_key +"\\"+cur_file_name
                with open(src_path, 'rb') as f_src:
                    data = f_src.read()
                    with open(dst_path, 'wb') as f_dst:
                        f_dst.write(data)
                        f_dst.close()
                    f_src.close()
                cur_CCT_key = ''
                cur_LV_key = ''
                cur_file_name = ''
        elif  cur_line_is_LV == 1:
            cur_LV = int(data_value)
            if cur_LV < 0:
                cur_LV_key = 'LV  -∞  ~  0'
            elif cur_LV < 20:
                cur_LV_key = 'LV =0 ~ 20'
            elif cur_LV < 40:
                cur_LV_key = 'LV =20 ~ 40'
            elif cur_LV < 60:
                cur_LV_key = 'LV =40 ~ 60'
            elif cur_LV < 80:
                cur_LV_key = 'LV =60 ~ 80'
            elif cur_LV < 100:
                cur_LV_key = 'LV =80 ~ 100'
            elif cur_LV < 120:
                cur_LV_key = 'LV =100 ~ 120'
            elif cur_LV < 140:
                cur_LV_key = 'LV =120 ~ 140'
            elif cur_LV < 160:
                cur_LV_key = 'LV =140 ~ 160'
            elif cur_LV < 180:
                cur_LV_key = 'LV =160 ~ 180'


def run_AWB():
    result_LV_0 = result_LV_obj()
    result_LV_1 = result_LV_obj()
    result_LV_2 = result_LV_obj()
    result_LV_3 = result_LV_obj()
    result_LV_4 = result_LV_obj()
    result_LV_5 = result_LV_obj()
    result_CCT = {
        "CCT  -∞  ~  2300": result_LV_0,
        "CCT =2300 ~ 2850": result_LV_1,
        "CCT =2850 ~ 3750": result_LV_2,
        "CCT =3750 ~ 5100": result_LV_3,
        "CCT =5100 ~ 6500": result_LV_4,
        "CCT =6500 ~   ∞": result_LV_5,
    }
    global photopath
    for cct_key in result_CCT:
        dir_name = photopath + "\\" + cct_key
        if os.path.isdir(dir_name):
            shutil.rmtree(dir_name)
    result_AE=["Face","Normal"]
    for cct_key in result_AE:
        dir_name = photopath + "\\" + cct_key
        if os.path.isdir(dir_name):
            shutil.rmtree(dir_name)
    child1_AWB = subprocess.Popen(
        f"{debug_Tool} -dump {photopath} -find \"AWB_TAG_CCT|AWB_TAG_ALGO_SCENE_LV\" -save {photopath}/")
    child1_AWB.wait()

    analyse_AWB(photopath,result_CCT)
    for cct_key in result_CCT:
        for lv_key in result_CCT[cct_key].result_LV:
            lv_count = result_CCT[cct_key].result_LV[lv_key]
            if os.path.exists(photopath+'\\'+ cct_key +'\\'+ lv_key) == False:
                if os.path.exists(photopath+'\\'+ cct_key) == False:
                    os.mkdir(photopath + '\\' + cct_key )
                os.mkdir(photopath+'\\'+ cct_key +'\\'+ lv_key)
            os.rename(photopath+'\\'+ cct_key +'\\'+ lv_key,
                    photopath+'\\'+ cct_key +'\\'+ '_'+str(lv_count)+'_'+lv_key)
    showinfo(title='提示', message='AWB分类 操作成功!')

# 初始化布局
root = tk.Tk()
root.title("AE_AWB图片分类小工具")

img_use_pic = open(r'C:PCBico.png', 'wb')  # 创建临时使用图片文件,这里放在了C盘的temp文件夹里
img_use_pic.write(base64.b64decode(img_pic))
img_use_pic.close()
image = tk.PhotoImage(file='C:PCBico.png')
root.iconphoto(False,image)
root.wm_iconphoto(False,image)
max_w, max_h = root.maxsize()
root.geometry(f'500x300+{int((max_w - 500) / 2)}+{int((max_h - 300) / 2)}')  # 居中
root.resizable(width=False, height=False)

# 初始化Entry控件
debug_entry = tk.StringVar()  # 选择目录信息
photo_entry = tk.StringVar()  # 输出路径信息

if os.path.exists(os.getcwd() + "\default_path.txt"):
    with open(os.getcwd() + "\default_path.txt", 'r') as f_default_path:
        lines = f_default_path.readlines()
        print(lines)
        for line in lines:
            if line.startswith("tool_deault_dir=") :
                default_tool_dir = line.split("tool_deault_dir=")[1].replace("\n", "")
                print(default_tool_dir)
                print(default_tool_dir)
                if "DebugParser.exe" in default_tool_dir:
                    debug_entry.set(default_tool_dir)
                    debug_Tool = default_tool_dir
            if line.startswith("photo_deault_dir=") :
                default_photo_dir = line.split("photo_deault_dir=")[1].replace("\n", "")
                if os.path.isdir(default_photo_dir):
                    photo_entry.set(default_photo_dir)
                    photopath = default_photo_dir


# === 布局控件
# raw路径 label
label = tk.Label(root, text="DP路径", font=("", 15))
label.place(x=50, y=80)

# 输入路径
raw_path = tk.Entry(root, textvariable=debug_entry, font=('', 15), width=20)
raw_path.place(x=130, y=80)

# 选择文件夹 按钮
button_raw = tk.Button(root, text="选择文件", command=select_tool_dir, font=('', 10), width=15)
button_raw.place(x=350, y=80)

# out路径 label
label2 = tk.Label(root, text="Pic路径", font=("", 15))
label2.place(x=50, y=160)

# out信息框
out_path = tk.Entry(root, textvariable=photo_entry, font=('', 15), width=20)
out_path.place(x=130, y=160)

button_raw = tk.Button(root, text="选择文件夹", command=select_picture_path, font=('', 10), width=15)
button_raw.place(x=350, y=160)


button_raw = tk.Button(root, text="运行AE分类", command=run_AE, font=('', 10), width=15)
button_raw.place(x=80, y=220)

button_raw = tk.Button(root, text="运行AWB分类", command=run_AWB, font=('', 10), width=15)
button_raw.place(x=240, y=220)
root.mainloop()
os.remove(r'C:PCBico.png')

要点1:Popen 调用windows工具,命令行可执行的命令

 subprocess.Popen(
        f"{debug_Tool} -dump {photopath} -find \"AWB_TAG_CCT|AWB_TAG_ALGO_SCENE_LV\" -save {photopath}/")

要点2:将图片文件转换为 py 文件,从代码中调用,方便打包

from png_resource import img as img_pic

root = tk.Tk()
img_use_pic = open(r'C:PCBico.png', 'wb')  # 创建临时使用图片文件,这里放在了C盘的temp文件夹里
img_use_pic.write(base64.b64decode(img_pic))
img_use_pic.close()
image = tk.PhotoImage(file='C:PCBico.png')
root.iconphoto(False,image)
root.wm_iconphoto(False,image)


os.remove(r'C:PCBico.png')  #结束时调用

要点3:python 用class 模拟C 语音的结构体,字典嵌套实现如下,可以都放入class 内部简化代码

class result_LV_obj:
    def __init__(self):
        self.result_LV = {
            "LV  -∞  ~  0" : 0,
            'LV =0 ~ 20'   : 0,
            'LV =20 ~ 40'  : 0,
            'LV =40 ~ 60'  : 0,
            'LV =60 ~ 80'  : 0,
            'LV =80 ~ 100' : 0,
            'LV =100 ~ 120': 0,
            'LV =120 ~ 140': 0,
            'LV =140 ~ 160': 0,
            'LV =160 ~ 180': 0,
        }
def run_AWB():
    result_LV_0 = result_LV_obj()
    result_LV_1 = result_LV_obj()
    result_LV_2 = result_LV_obj()
    result_LV_3 = result_LV_obj()
    result_LV_4 = result_LV_obj()
    result_LV_5 = result_LV_obj()
    result_CCT = {
        "CCT  -∞  ~  2300": result_LV_0,
        "CCT =2300 ~ 2850": result_LV_1,
        "CCT =2850 ~ 3750": result_LV_2,
        "CCT =3750 ~ 5100": result_LV_3,
        "CCT =5100 ~ 6500": result_LV_4,
        "CCT =6500 ~   ∞": result_LV_5,
    }

未解决问题:

         1. 原本采用 递归 遍历文件夹 的方式,每完成对当前文件的分类时直接修改目标文件夹名称;总是会提示文件夹仍然被占用错误。

         2. 后尝试递归函数放入单独的线程中执行,子线程遍历过程中维护2个列表,分别保存需要修改的文件名完整路径 和 重命名后的文件名完整路径,并在这个子线程结束调用后再遍历列表,对文件夹进行重命名,仍然有相同文件仍然被占用错误。主线程中在子线程结束后仍然加2秒延时,还是会有这个错误。。

        3. 尝试列表中直接写死直接对文件夹调用重命名,可以成功。。。未知文件被占用的根本原因。

        4. 文件被占用查询占用情况详细信息方法未尝试成功,待继续分析。文章来源地址https://www.toymoban.com/news/detail-610062.html

到了这里,关于Python tkinker 界面设计与图标设置和图片文件打包成单个exe的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • python美化图形化界面设计,pythontkinter界面美化

    大家好,本文将围绕python美化图形化界面设计展开说明,pythontkinter界面美化是一个很多人都想弄明白的事情,想搞清楚python美化输出模块需要先了解以下几个事情。 PyQt,一个基于Qt的Python接口包,可以直接使用Qt的控件薯轿茄,还可以使用QSS进行界面美化,下面我简单介绍一

    2024年02月08日
    浏览(43)
  • Python | 人脸识别系统 — UI界面设计

    博客汇总:Python | 人脸识别系统 — 博客索引 GitHub地址:Su-Face-Recognition 注:阅读本博客前请先参考 工具安装、环境配置:Python | 人脸识别系统 — 简介         本项目采用PyQt库作为UI界面的编写,使用Qt-Designer、PyUIC自动生成UI界面代码。 关于PyQt库的详细使用可以参考该系

    2024年02月12日
    浏览(41)
  • Python编程:Tkinter图形界面设计(1)

    目录 一、Tkinter的程序框架  二、窗口内容 2.1 窗口的几何尺寸 2.2 窗口的摆放位置 2.3  实验代码 2.4 控件管理 三、控件编程 窗口的生成和窗口的呈现,用Tk()和mainloop()包括起来,中间程序是附着在窗口的内部部件。 ​ 窗口的内容,是最丰富的细节包括:1、几何尺寸 2、按钮

    2024年02月07日
    浏览(55)
  • Python QT5设计UI界面教程

    简介:PyQT5开发常用知识,零基础上手,需配合我之前写的博文,配置好QT设计工具和ui文件转py文件的工具。博文为:使用Python PyQt5实现一个简单的图像识别软件;页面效果如下: 1.设计菜单栏 Containers——Tab Widget; 2.横向排布  可以自动水平对齐 3.文本框和选择框 4.日期输入

    2024年01月17日
    浏览(44)
  • 【Python入门系列】第八篇:Python中GUI编程和图形界面设计

    Python中的GUI编程是指使用Python语言创建图形用户界面(GUI)的过程。通过GUI,用户可以与程序进行交互,通过按钮、菜单、文本框等控件来操作程序。 Python提供了多个库和框架来实现GUI编程,其中最常用的是Tkinter、wxPython、PyQt和PyGTK等。这些库提供了丰富的控件和功能,使开

    2024年02月07日
    浏览(51)
  • Python学习笔记--exe文件打包与UI界面设计

    又是半年时间过去了,终于有有时间摸鱼学一点python了。本次练习主要针对之前写过的自动打卡脚本,将其打包成exe文件,并加上UI界面。其实对于自动打卡这个功能来说,UI界面并不是必需品,加上了界面反而有些麻烦。 我比较熟悉的UI相关的库主要有 easygui,tkinter,pyqt5

    2024年02月05日
    浏览(38)
  • 数据库课程设计 python+mysql+图形化界面

    进行操作的表   增加界面   删除界面   修改界面    查找界面  

    2024年02月09日
    浏览(40)
  • Python图形用户界面设计-Delphi For Python高级开发教程

    目录 简介........................................................................ 5 谁应该阅读这本教程........................................................ 5 第1章 Python与Delphi...................................................... 6 什么是Delphi4Python....................................................... 6 1.1 Python语言介绍....

    2024年02月07日
    浏览(73)
  • 人脸识别系统OpenCV+dlib+python(含数据库)Pyqt5界面设计 项目源码 毕业设计

    Python语言、dlib、OpenCV、Pyqt5界面设计、sqlite3数据库      本系统使用dlib作为人脸识别工具,dlib提供一个方法可将人脸图片数据映射到128维度的空间向量,如果两张图片来源于同一个人,那么两个图片所映射的空间向量距离就很近,否则就会很远。因此,可以通过提取图片并

    2024年02月05日
    浏览(63)
  • Python 使用tkinter设计Windows网页或应用的用户注册登录界面

    上一篇:Python 自定义模块和包设计英语生词本(文件版)-CSDN博客 紧接上一篇博文,当我们熟练掌握自定义模块和包、掌握文件的的读取与写入、掌握正则表达式内置模块\\\"re\\\"、掌握GUI(图形界面)的部分组件后,接着我们将要以上的知识点结合起来,设计一个GUI(图形界面

    2024年02月03日
    浏览(48)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包