I created an application which reads a text file and displays results in GUI based on the values in text file. The code is working fine with spyder (Anaconda3). However when I create exe using pyinstaller, the exe is only showing a black screen without opening GUI. Code is given below.
Can anyone help me on this.
import os
import pandas as pd
from tkinter import *
# importing askopenfile function from class filedialog
from tkinter.filedialog import askopenfile
# Define variables to store values
UCMAX = int
UCMIN = int
TOT_VOL = float
#Function for deleting initial lines from original mms file and storing as dummy file
def delete_multiple_lines(original_file,dummy_file, line_numbers):
"""In a file, delete the lines at line number in given list"""
is_skipped = False
counter = 0
# Open original file in read only mode and dummy file in write mode
with open(original_file, 'r') as read_obj, open(dummy_file, 'w') as write_obj:
# Line by line copy data from original file to dummy file
for line in read_obj:
# If current line number exist in list then skip copying that line
if counter not in line_numbers:
write_obj.write(line)
else:
is_skipped = True
counter += 1
def Evaluate_file():
file = askopenfile(filetypes =[('txt Files', '*.txt')])
if file:
# create a list
lines = []
# Store range of lines to be deleted
for i in range(0,71,1):
lines.append(i)
# Call delete line function with argument main text, dummy text files, initial rows to be deleted
delete_multiple_lines(os.path.basename(
file.name),'dummy.txt',lines)
#Read text file
data = pd.read_fwf('dummy.txt',col_index=0,delim_whitespace=True,skipinitialspace =True,skip_blank_lines=True)
#Delete invalid/unrequired rows
data = data.dropna()
#Delete second column which is not useful
data = data.drop([0, 1])
# Create Index column for better analysis
data = data.reset_index()
# Delete initial index column as the number is not continuous due to deletion of unwanted rows
data = data.drop(['index'], axis = 1)
# Create Column Header row
data.columns=["Status", "Values", "State", "CF", "G2M", "M2G", "OV", "UV", "Bypass_OWN", "BYPASS_PARTNER", "TEMP_ERR", "TEMP_HIGH1", "TEMP_HIGH2", "DRV_PWR", "UCE_SAT", "DCiUV", "DCiOV", "COMFLT_MI2GIB_COMFLT_GIB2MI", "COMFLTCntSUM_MI2GIB_COMFLTCntSUM_GIB2MI"]
# Split the Values column as so many fields are merged while reading and store in new dataframe
data1 = data["Values"].str.split(" ",expand=True,)
#Delete unwanted columns in new Data frame with split fields
data1 = data1.drop([0,3, 5,7,8,10,11,12,13,15,16,17,18],axis=1)
# Remove unwanted : in sub module number field
data1[1] = data1[1].str.replace(':','')
data1.columns=["SM_NUMBER","HEX1","HEX2","Operational","Voltage","Present_status"]
# Delete the values column with so many fields & status column in original data frame which are not required
data = data.drop(['Values'],axis=1)
data = data.drop(['Status'],axis=1)
# Merge temporary dataframe with splitted fields of values and original dataframe
data = pd.concat([data1,data],axis=1)
#Query for modules in block status and strore in dataframe
data1=data.query(' Present_status == "HB_BLOCK" ')
# Remove V from Voltage field
data["Voltage"] = data["Voltage"].str.replace('V','')
# Convert Voltage field to number
data["Voltage"] = data["Voltage"].astype(int)
#Find UC Max
# print("UCMAX: ", data["Voltage"].max(), "Volts")
UCMAX=data.loc[data["Operational"]=="Operational",'Voltage'].max()
#Find UC Min
UCMIN=data.loc[data["Operational"]=="Operational",'Voltage'].min()
# Find total voltage in arm by adding voltages of capacitors whose SM status is ON
TOT_VOL=data.loc[data["Present_status"]=="HB_ON",'Voltage'].sum()/1000
data2 = data1[['SM_NUMBER','Operational','Present_status']]
print ("\n Blocked submodules:\n", data2)
#Update text boxes
T1.delete("insert linestart", "insert lineend")
T1.insert(END, UCMAX)
T2.delete("insert linestart", "insert lineend")
T2.insert(END, UCMIN)
T3.delete("insert linestart", "insert lineend")
T3.insert(END, TOT_VOL)
T4.delete('1.0', END)
T4.insert(END, data2)
root = Tk()
root.geometry('600x600')
var = StringVar()
label = Label( root, textvariable=var, relief=RAISED )
var.set("Details will be displayed below after opening file")
label.pack(pady=20)
btn = Button(root, text ='File Open ...', command = lambda:Evaluate_file())
btn.pack(side = TOP, pady = 10)
lbl1=Label(root, text='UCMAX in Volts').pack()
T1 = Text(root, height=1, width=10)
T1.pack(pady=10)
lbl2=Label(root, text='UCMIN in Volts').pack()
T2 = Text(root, height=1, width=10)
T2.pack(pady=10)
lbl3=Label(root, text='TOTAL ARM VOLTAGE in Kilo Volts').pack()
#lbl3.pack(side = LEFT)
T3 = Text(root, height=1, width=10)
T3.pack(pady=10)
lbl3=Label(root, text='Abnormalities').pack()
#lbl3.pack(side = LEFT)
T4 = Text(root, height=10, width=70)
T4.pack(pady=10)
mainloop()