from win32com import client as wc from docx import Document from get_imformation import MainWindow # 文档处理工具 from tools.document_tools import ( create_document, add_documents, add_table_to_document,right_align_last_three_para ) # 内容处理工具 from tools.content_tools import ( add_picture, search_and_replace,add_picture_to_table ) from get_pictures import make_Thumbnail,get_picture_nums,resize_and_reduce_quality from core.tables import fill_tables async def add_dynamic_table(output_doc,output_dir,table_num,TABLES,JIANCHA_XIANGQING_DIR,PICTURES,row,col,i,FLAG): """创建动态表 Args: output_doc (Document): 文档对象 output_dir (str): 输出目录 table_num (int): 表格序号 TABLES (list): 表格数据 JIANCHA_XIANGQING_DIR (str): 检查详情表目录 PICTURES (list): 图片数据 row (int): 行数 col (int): 列数 i (int): 表格序号 """ for Table in TABLES: print(Table) output_doc, message = await add_table_to_document(output_dir, JIANCHA_XIANGQING_DIR,row,col,i,Table,FLAG) print(message) print(f"开始处理图片列表{PICTURES}") try: for picturedir in PICTURES[table_num][0]: print(f"添加 {picturedir} {type(picturedir)}到表格{table_num}") resize_and_reduce_quality(picturedir,picturedir) print(await add_picture_to_table(output_doc, output_dir, 2, 0, picturedir, i, 4.7232)) except Exception as e: print(f"添加图片失败:{e}") table_num += 1 if table_num == len(PICTURES[table_num]): table_num = 0 i += 1 if i%2 == 1: output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.save(output_dir) return i,table_num def break_across_pages(p): word = wc.Dispatch('Word.Application') word.Visible = False word.DisplayAlerts = False doc = word.Documents.Open(p) try: for table in doc.Tables: table.Rows.AllowBreakAcrossPages = False doc.Save() finally: doc.Close() async def test(output_dir, cover_dirs, page_cut = True): # 创建一个新文档作为基础 merged_document = Document() for file in cover_dirs: doc = Document(file) # 复制源文档中的所有段落 for element in doc.element.body: # 复制每个元素到合并后的文档 merged_document.element.body.append(element) # 保存合并后的文档 merged_document.save(output_dir) Picture_dir = "" jituan_name=fengchang_name=project_number=jizu_type=company_name_yi=company_name_jia=project_location=fuzeren=phone_fuzeren=Y1=Y2=Y3=xiangmuguige = "" JIANCHA_XINGXI42 = "" #生成报告 async def main(ui): #报告内容是否展示 Project_Overview = True global Picture_dir global jituan_name, fengchang_name, project_number, jizu_type, company_name_yi, company_name_jia, project_location, fuzeren, phone_fuzeren, Y1, Y2, Y3, xiangmuguige title_report = jituan_name+project_number #获取模板编号、模板名称 cover_encode = "encode" cover_project = "project" cover_date = "time" TITLE_OF_REPORT = "companyencode" ###封面创建### #封面目录 cover_dirs = [r"C:\Users\DTAI\Desktop\work\报告生成\封面\外部封面1.docx",r"C:\Users\DTAI\Desktop\work\报告生成\封面\封面图片.jpg",r"C:\Users\DTAI\Desktop\work\报告生成\封面\外部封面2.docx"] #输出目录 output_dir = fr"C:\Users\DTAI\Desktop\work\报告生成\{jituan_name}{fengchang_name}项目风力发电机组叶片检查报告{project_number}.docx" #创建文档、添加封面 print(await create_document(output_dir)) print(await add_documents(output_dir, cover_dirs[0])) print(await add_picture(output_dir, cover_dirs[1])) print(await add_documents(output_dir, cover_dirs[2])) print("封面创建成功") #更改文档信息 print(await search_and_replace(output_dir, TITLE_OF_REPORT, jituan_name + project_number)) print(await search_and_replace(output_dir, cover_project, jituan_name + fengchang_name)) print(await search_and_replace(output_dir, cover_encode, jituan_name + project_number)) print(await search_and_replace(output_dir, cover_date, date)) ###封面创建### XIANG_MU_GAI_KUANG = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\项目概括表.docx" XIANGMU_GAIKUO = list(list("" for i in range(5)) for j in range(5)) XIANGMU_GAIKUO[0][1] = fengchang_name #XIANGMU_GAIKUO[0][3]=XIANGMU_GAIKUO[0][4] = "盐城市滨海县" XIANGMU_GAIKUO[0][3] = project_location #XIANGMU_GAIKUO[1][1]=XIANGMU_GAIKUO[2,1]=XIANGMU_GAIKUO[3,1] = "国家电投集团滨海风力发电有限公司" XIANGMU_GAIKUO[1][1] = company_name_jia XIANGMU_GAIKUO[1][3] = company_name_yi XIANGMU_GAIKUO[2][3] = fuzeren XIANGMU_GAIKUO[3][4] = phone_fuzeren XIANGMU_GAIKUO[4][1] = jizu_type XIANGMU_GAIKUO[4][4] = xiangmuguige JIANCHA_XINGXI_DIR = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\检查信息表.docx" JIANCHA_XINGXI = list(list("" for i in range(4)) for j in range(9)) Jiancha_renyuan = "张三" Jiancha_shijian = "2025年4月28日" YepianChangjia = "株洲时代新材料科技股份有限公司" Yepianxingxi1 = f"机组编号{project_number}机组" Yepianxingxi2 = f"叶片1:{Y1}" Yepianxingxi3 = f"叶片2:{Y2}" Yepianxingxi4 = f"叶片3:{Y3}" normal_picture_num = get_picture_nums(Picture_dir) Y1_quexian_num = get_picture_nums(Picture_dir + rf"\{Y1}\缺陷图") Y2_quexian_num = get_picture_nums(Picture_dir + rf"\{Y2}\缺陷图") Y3_quexian_num = get_picture_nums(Picture_dir + rf"\{Y3}\缺陷图") picture_num = normal_picture_num JIANCHA_XINGXI[0][1] = Jiancha_renyuan JIANCHA_XINGXI[1][1] = Jiancha_shijian JIANCHA_XINGXI[1][3] = jituan_name+project_number JIANCHA_XINGXI[3][2] = YepianChangjia JIANCHA_XINGXI[4][1] = Yepianxingxi1 JIANCHA_XINGXI[5][1] = Yepianxingxi2 JIANCHA_XINGXI[6][1] = Yepianxingxi3 JIANCHA_XINGXI[7][1] = Yepianxingxi4 JIANCHA_XINGXI[8][0] = f"本次无人机叶片外部高精度飞行检查,采集叶片图片{picture_num}张,内容覆盖A、B、C三支叶片的前缘、后缘、迎风面、背风面。" global JIANCHA_XINGXI42 JIANCHA_XINGXI42 = r"C:\Users\DTAI\Desktop\work\报告生成\图片\检查信息表4,2图.jpg" CHENGGUO_DIJIAO_DIR = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\成果递交表.docx" CHENGGUO_DIJIAO = list(list("" for i in range(4)) for j in range(6)) Yezhurenyuan = "李四" Shujuchuli_renyuan = "王五" Baogaobianzhi_renyuan = "六麻子" Baogaoshenghe_renyuan = "六麻子" Changjia_renyuan = "无" Juti_shijian = "15:00" Chuli_shijian = "2025年4月30日" Bianzhi_shijian = "2025年4月30日" Shenghe_shijian = "2025年5月28日" CHENGGUO_DIJIAO[0][1] = Jiancha_renyuan CHENGGUO_DIJIAO[1][1] = Yezhurenyuan CHENGGUO_DIJIAO[2][1] = Jiancha_shijian CHENGGUO_DIJIAO[3][1] = Shujuchuli_renyuan CHENGGUO_DIJIAO[4][1] = Baogaobianzhi_renyuan CHENGGUO_DIJIAO[5][1] = Baogaoshenghe_renyuan CHENGGUO_DIJIAO[1][3] = Changjia_renyuan CHENGGUO_DIJIAO[2][3] = Juti_shijian CHENGGUO_DIJIAO[3][3] = Chuli_shijian CHENGGUO_DIJIAO[4][3] = Bianzhi_shijian CHENGGUO_DIJIAO[5][3] = Shenghe_shijian JIANCHA_HUIZONG_DIR = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\检查情况汇总表.docx" JIANCHA_HUIZONG = list(list("" for i in range(3)) for j in range(4)) Y1_Jiancha_neirong = "前缘、后缘、PS面、SS面" Y2_Jiancha_neirong = "前缘、后缘、PS面、SS面" Y3_Jiancha_neirong = "前缘、后缘、PS面、SS面" Y1_Wenti = """1.距叶根20m处,叶片PS面发现1处裂纹损伤长度为轴向3m 2.距叶根30m处,叶片后缘发现一处涂层损伤长度为轴向120mm。""" Y2_Wenti = "未发现明显影响风力发电机组正常运行的外部缺陷" Y3_Wenti = "未发现明显影响风力发电机组正常运行的外部缺陷" JIANCHA_HUIZONG[1][0] = f"{Y1} 共发现缺陷{Y1_quexian_num}处" JIANCHA_HUIZONG[2][0] = f"{Y2} 共发现缺陷{Y2_quexian_num}处" JIANCHA_HUIZONG[3][0] = f"{Y3} 共发现缺陷{Y3_quexian_num}处" JIANCHA_HUIZONG[1][1] = f"叶片{Y1_Jiancha_neirong}" JIANCHA_HUIZONG[2][1] = f"叶片{Y2_Jiancha_neirong}" JIANCHA_HUIZONG[3][1] = f"叶片{Y3_Jiancha_neirong}" JIANCHA_HUIZONG[1][2] = Y1_Wenti JIANCHA_HUIZONG[2][2] = Y2_Wenti JIANCHA_HUIZONG[3][2] = Y3_Wenti JIANCHA_NEIRONG_DIR = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\检查内容表.docx" JIANCHA_NEIRONG = list(list("" for i in range(3)) for j in range(15)) JIANCHA_NEIRONG[0][0] = f"叶片:1#({Y1})检查结果" JIANCHA_NEIRONG[5][0] = f"叶片:2#({Y2})检查结果" JIANCHA_NEIRONG[10][0] = f"叶片:3#({Y3})检查结果" Y1_Jiancha_Tupian1_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y1}\图片1.jpg" Y1_Jiancha_Tupian2_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y1}\图片2.jpg" Y1_Jiancha_Tupian3_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y1}\图片3.jpg" Y1_Jiancha_Tupian4_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y1}\图片4.jpg" Y1_Jiancha_Tupian5_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y1}\图片5.jpg" Y1_Jiancha_Tupian6_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y1}\图片6.jpg" Y2_Jiancha_Tupian1_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y2}\图片1.jpg" Y2_Jiancha_Tupian2_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y2}\图片2.jpg" Y2_Jiancha_Tupian3_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y2}\图片3.jpg" Y2_Jiancha_Tupian4_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y2}\图片4.jpg" Y2_Jiancha_Tupian5_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y2}\图片5.jpg" Y2_Jiancha_Tupian6_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y2}\图片6.jpg" Y3_Jiancha_Tupian1_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y3}\图片1.jpg" Y3_Jiancha_Tupian2_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y3}\图片2.jpg" Y3_Jiancha_Tupian3_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y3}\图片3.jpg" Y3_Jiancha_Tupian4_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y3}\图片4.jpg" Y3_Jiancha_Tupian5_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y3}\图片5.jpg" Y3_Jiancha_Tupian6_Dir = rf"C:\Users\DTAI\Desktop\work\报告生成\机组外部\{Y3}\图片6.jpg" JIANCHA_XIANGQING_TITLE_DIR = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\检查详情标题.docx" JIANCHA_XIANGQING_DIR = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\检查详情表.docx" """ 动态表思路 后端直接获取每个叶片的缺陷总数返回给前端。(TABLE_NUMS) 前端根据缺陷总数给用户提示填写每个表格的表单。 前端返回数据 Y1_table_list [ [ 缺陷类型: 缺陷位置: 缺陷尺寸: 危重等级: 图片路径: ] [ 缺陷类型: 缺陷位置: 缺陷尺寸: 危重等级: 图片路径: ] ... ] 这个数据也可以作为检查情况汇总的数据来源,即可先让用户标注对应缺陷图的缺陷,存放后进行表格填写。 最后后端读取表单数据,生成表格并插入到文档中。 或者: 缺陷在文件名上已经写好,前端直接读取文件名,根据文件名生成对应的表单。 """ Y1_table_list = [ { "QueXianLeiXing" : "涂层损伤", "QueXianWeiZhi" : "叶片ps面距叶根3m处", "QueXianChiCun" : "弦向100mm,轴向800mm", "WeiZongDengJi" : "轻微", "Tupian_Dir" : [r"C:\Users\DTAI\Desktop\work\报告生成\机组外部\1L-3-1#\缺陷图\1L-3-1#,叶片ps面距叶根3m处,涂层损伤,缺陷尺寸弦向100mm,轴向800mm。DJI_20250319155824_0062_Z.jpg"], }, { "QueXianLeiXing" : "涂层损伤", "QueXianWeiZhi" : "叶片ps面距叶根3m处", "QueXianChiCun" : "弦向100mm,轴向800mm", "WeiZongDengJi" : "轻微", "Tupian_Dir" : [r"C:\Users\DTAI\Desktop\work\报告生成\机组外部\1L-3-1#\缺陷图\1L-3-1#,叶片ps面靠近前缘距叶根1m处,涂层损伤,缺陷尺寸弦向80mm,轴向300mm。DJI_20250319155842_0067_Z.jpg"], } ] Y2_table_list = [ { "QueXianLeiXing" : "涂层损伤", "QueXianWeiZhi" : "叶片ps面距叶根3m处", "QueXianChiCun" : "弦向100mm,轴向800mm", "WeiZongDengJi" : "轻微", "Tupian_Dir" : [r"C:\Users\DTAI\Desktop\work\报告生成\机组外部\1L-3-1#\缺陷图\1L-3-1#,叶片ps面距叶根3m处,涂层损伤,缺陷尺寸弦向100mm,轴向800mm。DJI_20250319155824_0062_Z.jpg"], }, { "QueXianLeiXing" : "涂层损伤", "QueXianWeiZhi" : "叶片ps面距叶根3m处", "QueXianChiCun" : "弦向100mm,轴向800mm", "WeiZongDengJi" : "轻微", "Tupian_Dir" : [r"C:\Users\DTAI\Desktop\work\报告生成\机组外部\1L-3-1#\缺陷图\1L-3-1#,叶片ps面靠近前缘距叶根1m处,涂层损伤,缺陷尺寸弦向80mm,轴向300mm。DJI_20250319155842_0067_Z.jpg"], } ] Y3_table_list = [ { "QueXianLeiXing" : "涂层损伤", "QueXianWeiZhi" : "叶片ps面距叶根3m处", "QueXianChiCun" : "弦向100mm,轴向800mm", "WeiZongDengJi" : "轻微", "Tupian_Dir" : [r"C:\Users\DTAI\Desktop\work\报告生成\机组外部\1L-3-1#\缺陷图\1L-3-1#,叶片ps面距叶根3m处,涂层损伤,缺陷尺寸弦向100mm,轴向800mm。DJI_20250319155824_0062_Z.jpg"], }, { "QueXianLeiXing" : "涂层损伤", "QueXianWeiZhi" : "叶片ps面距叶根3m处", "QueXianChiCun" : "弦向100mm,轴向800mm", "WeiZongDengJi" : "轻微", "Tupian_Dir" : [r"C:\Users\DTAI\Desktop\work\报告生成\机组外部\1L-3-1#\缺陷图\1L-3-1#,叶片ps面靠近前缘距叶根1m处,涂层损伤,缺陷尺寸弦向80mm,轴向300mm。DJI_20250319155842_0067_Z.jpg"], } ] Xu_Hao = 0 #单后端测试变量 Y1_TABLE_NUMS = len(Y1_table_list) Y2_TABLE_NUMS = len(Y2_table_list) Y3_TABLE_NUMS = len(Y3_table_list) Y1_TABLES, Y1_TABLES_PICTURES, Xu_Hao = fill_tables(Y1_table_list,6,3,Y1_TABLE_NUMS,Xu_Hao,Y1) Y2_TABLES, Y2_TABLES_PICTURES, Xu_Hao = fill_tables(Y2_table_list,6,3,Y2_TABLE_NUMS,Xu_Hao,Y2) Y3_TABLES, Y3_TABLES_PICTURES, Xu_Hao = fill_tables(Y3_table_list,6,3,Y3_TABLE_NUMS,Xu_Hao,Y3) #总结文字 ZONG_JIE_BEFORE = "result" ZONG_JIE = """1、因海上风电叶片运行环境恶劣、空气盐碱度高,叶片前缘合模缝区域及PS面(迎风面)涂层易受腐蚀,建议定期观察维护。 2、经无人机近距离外观检查发现H3-08#机位Y200220AF叶片PS面距叶根20m处发现一处裂纹,损伤长度轴向3m,该缺陷经我方判定为严重缺陷,建议尽快结安排对该机组停机并结合其他检查手段(如人工打磨)进一步勘查并决定维修处置方案,防止风险进一步升级。 3、经无人机近距离外观检查未发现H3-08#机位Y200249AF、Y200250AF叶片有明显影响机组正常运行的外部缺陷。 """ ZONG_JIE_DIR = r"C:\Users\DTAI\Desktop\work\报告生成\外部报告表格\总结.docx" i = 0 #添加项目概况表 output_doc, message = await add_table_to_document(output_dir, XIANG_MU_GAI_KUANG,5,5,i,XIANGMU_GAIKUO) print(message) i += 1 #新建检查信息表 output_doc, message = await add_table_to_document(output_dir, JIANCHA_XINGXI_DIR,9,4,i,JIANCHA_XINGXI,False) print(message) Thumbnail_Picture = await make_Thumbnail(Picture_dir, Picture_dir) #添加图片 print(await add_picture_to_table(output_doc, output_dir, 4, 2, JIANCHA_XINGXI42, i)) #添加略缩图片 print(await add_picture_to_table(output_doc, output_dir, 8, 0, Thumbnail_Picture, i)) i += 1 #添加成果递交表 output_doc, message = await add_table_to_document(output_dir, CHENGGUO_DIJIAO_DIR,5,5,i,CHENGGUO_DIJIAO,True,0.04) print(message) i += 1 #添加检查情况汇总表 output_doc, message = await add_table_to_document(output_dir, JIANCHA_HUIZONG_DIR,4,3,i,JIANCHA_HUIZONG,False) print(message) i += 1 #添加检查内容表 output_doc, message = await add_table_to_document(output_dir, JIANCHA_NEIRONG_DIR,15,3,i,JIANCHA_NEIRONG,False) print(message) print(await add_picture_to_table(output_doc, output_dir, 1, 0, Y1_Jiancha_Tupian1_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 1, 1, Y1_Jiancha_Tupian2_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 1, 2, Y1_Jiancha_Tupian3_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 3, 0, Y1_Jiancha_Tupian4_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 3, 1, Y1_Jiancha_Tupian5_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 3, 2, Y1_Jiancha_Tupian6_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 6, 0, Y2_Jiancha_Tupian1_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 6, 1, Y2_Jiancha_Tupian2_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 6, 2, Y2_Jiancha_Tupian3_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 8, 0, Y2_Jiancha_Tupian4_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 8, 1, Y2_Jiancha_Tupian5_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 8, 2, Y2_Jiancha_Tupian6_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 11, 0, Y3_Jiancha_Tupian1_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 11, 1, Y3_Jiancha_Tupian2_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 11, 2, Y3_Jiancha_Tupian3_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 13, 0, Y3_Jiancha_Tupian4_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 13, 1, Y3_Jiancha_Tupian5_Dir, i)) print(await add_picture_to_table(output_doc, output_dir, 13, 2, Y3_Jiancha_Tupian6_Dir, i)) i += 1 #添加检查详情表 """ 分页符无法加入,python-docx库原因 """ output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.add_paragraph('\u200B') output_doc.save(output_dir) print(await add_documents(output_dir, JIANCHA_XIANGQING_TITLE_DIR)) table_num = 0 i,table_num = await add_dynamic_table(output_doc,output_dir,table_num,Y1_TABLES,JIANCHA_XIANGQING_DIR,Y1_TABLES_PICTURES,3,6,i,False) i,table_num = await add_dynamic_table(output_doc,output_dir,table_num,Y2_TABLES,JIANCHA_XIANGQING_DIR,Y2_TABLES_PICTURES,3,6,i,False) i,table_num = await add_dynamic_table(output_doc,output_dir,table_num,Y3_TABLES,JIANCHA_XIANGQING_DIR,Y3_TABLES_PICTURES,3,6,i,False) break_across_pages(output_dir) #添加总结 print(await add_documents(output_dir, ZONG_JIE_DIR)) print(await search_and_replace(output_dir, ZONG_JIE_BEFORE, ZONG_JIE)) print(await right_align_last_three_para(output_dir)) # for Table in Y1_TABLES: # print(Table) # output_doc, message = await add_table_to_document(output_dir, JIANCHA_XIANGQING_DIR,3,6,i,Table,False) # print(message) # try: # for picturedir in Y1_TABLES_PICTURES[table_num][0]: # print(f"添加 {picturedir} {type(picturedir)}到表格") # resize_and_reduce_quality(picturedir,picturedir) # print(await add_picture_to_table(output_doc, output_dir, 2, 0, picturedir, i, 6)) # except Exception as e: # print(f"添加图片失败:{e}") # table_num += 1 # i += 1 #添加 if "__main__" == __name__: import sys from PySide6 import QtWidgets app = QtWidgets.QApplication(sys.argv) # 创建一个QApplication,也就是你要开发的软件app Window = MainWindow() # 创建一个QMainWindow,也就是你要开发的软件的主窗口 Window.show() # 执行QMainWindow的show()方法,显示这个QMainWindow sys.exit(app.exec()) # 使用exit()或者点击关闭按钮退出QApplication