问题背景:
该程序是一个借助ttkbootstrap框架写的GUI程序界面,其中texbox为文本框,可以写入文本内容
问题描述:
在执行start函数时,代码并没有按照缩写的逻辑进行运行。
理想情况下,按照逻辑运行为:实例化一个类,文本框中写入content1 ->执行类的esp_radar()方法,文本框中写入content2 ->执行类的方法, 写入contentn。
实际运行情况:将类中所有的方法全部都执行完毕之后,才开始向文本框中写入内容。
为什么我会发现是在所有方法都执行完毕之后,才开始向文本框中写入内容的呢?因为我在每个方法中都写入了print函数,终端显示是打印了每个函数内部的内容,然后GUI界面中才开始写入内容。
由于隐私需要,我将大部分的函数代码隐去,仅保留部分,求各位大佬指点![Python] 纯文本查看 复制代码 from datetime import datetime
import os
from tkinter.scrolledtext import ScrolledText
from tkinter.filedialog import askopenfilename, askdirectory
# 导入第三方模块
from ttkbootstrap.constants import *
import ttkbootstrap as ttk
from PIL import Image as P_Image # 直接导入Image会与tkinterImage产生冲突,导致无open方法
from PIL import ImageTk
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import ticker
import matplotlib.patches as mpatches
from openpyxl import Workbook, load_workbook
from openpyxl.styles import colors
from openpyxl.styles import Font, Border, Side
from openpyxl.styles import PatternFill, Alignment
from openpyxl.drawing.image import Image
from openpyxl.utils import column_index_from_string
class WellProfileAnalysis:
def __init__(self, filepath):
print("{:*^50}".format("程序初始化完成"))
def well_lift_judge(self, df):
pass
def well_lift_classification(self):
"""油井举升分类"""
print("{:*^50}".format("油井举升分类完成"))
def esp_radar(self):
"""ESP运转天数雷达图"""
print("{:*^50}".format("ESP运转天雷达图完成"))
def tempture_pressure(self):
"""油井油套温压监控图"""
print("{:*^50}".format("油井油套温压监控完成"))
def pump_impeller(self, pump_path):
print("{:*^50}".format("井下电泵叶轮工况完成-输出图件"))
def impeller_excel_beautify(self):
pass
def pump_use_times(self):
pass
print("{:*^50}".format("双泵使用启停次数完成"))
def pump_system_job_account(self):
print("{:*^50}".format("双泵系统工作统计完成"))
def pump_efficiency(self, pump_path):
print("{:*^50}".format("泵举升效率完成"))
def motor_efficiency(self, pump_path):
print("{:*^50}".format("马达效率完成"))
def motor_load_ratio(self, pump_path):
print("{:*^50}".format("马达负载率完成"))
def motor_tempture_radar(self):
print("{:*^50}".format("马油田马达温度分析完成"))
def sand_production(self):
print("{:*^50}".format("出砂情况(质量比)完成"))
def generate_spreadsheet(self):
print("{:*^50}".format("输出报表表格完成"))
class Report(ttk.Frame):
def __init__(self, master, **kwargs):
super().__init__()
self.create_widgets()
def create_widgets(self):
pass
def open_file(self):
pass
def read_pump_data(self):
pass
def open_directory(self):
pass
def start_IPM(self, events):
pass
def start(self):
"""启动程序,开始处理,生成图片与叶轮工况表格"""
well = WellProfileAnalysis(self.daily_path)
# texbox.configure(state='normal')
# texbox.delete(1.0, END)
content1 = "程序初始化完成"
texbox.insert(END, f"{content1:*^50}\n")
well.esp_radar()
content2 = "运转天雷达处理完成"
texbox.insert(END, f"{content2:*^50}\n")
well.well_lift_classification()
content3 = "油井举升分类处理完成"
texbox.insert(END, f"{content3:*^50}\n")
well.pump_system_job_account()
content4 = "双泵系统工作统计处理完成"
texbox.insert(END, f"{content4:*^50}\n")
well.pump_efficiency(pump_path=self.pump_path)
content5 = "泵举升效率处理完成"
texbox.insert(END, f"{content5:*^50}\n")
well.pump_use_times()
content6 = "双泵使用启停次数处理完成"
texbox.insert(END, f"{content6:*^50}\n")
well.motor_efficiency(pump_path=self.pump_path)
content7 = "马达效率处理完成"
texbox.insert(END, f"{content7:*^50}\n")
well.sand_production()
content8 = "出砂情况处理完成"
texbox.insert(END, f"{content8:*^50}\n")
well.pump_impeller(pump_path=self.pump_path)
well.impeller_excel_beautify()
content9 = "井下电泵叶轮工况处理完成"
texbox.insert(END, f"{content9:*^50}\n")
well.motor_load_ratio(pump_path=self.pump_path)
content10 = "马达负载率处理完成"
texbox.insert(END, f"{content10:*^50}\n")
well.motor_tempture_radar()
content11 = "油田马达温度分析处理完成"
texbox.insert(END, f"{content11:*^50}\n")
well.tempture_pressure()
content12 = "油套温压处理完成"
texbox.insert(END, f"{content12:*^50}\n") |