0

I have a script that takes two excel files with two datasets and concatenates them and transforms various aspects of the resulting single data frame. I created this script in Jupyter Notebook. I want the person I am building this for to be able to utilize this script without having to interact with the Python. I am trying to figure out how to create a GUI that browses through one's files and allows you to bring in the two excel sheets, and then passes them to the script to be brought in as dataframes.

Currently I have some code copied from PySimpleGUI that allows me to browse and select two files. However I still am not sure how to pass the inputs from the GUI to my original script for transformation. Any advice would be greatly appreciated!

'''

Read in excel sheets

import PySimpleGUI as sg

GUI Code from PySimpleGUI

sg.theme('Light Blue 2')

layout = [[sg.Text('Enter 2 files to comare')],
          [sg.Text('File 1', size=(8, 1)), sg.Input(), sg.FileBrowse()],
          [sg.Text('File 2', size=(8, 1)), sg.Input(), sg.FileBrowse()],
          [sg.Submit(), sg.Cancel()]]
print(layout[2])
window = sg.Window('File Compare', layout)

event, values = window.read()
window.close()

print(f'You clicked {event}')
print(layout[2])

Original Code

df1 = pd.read_excel("C:/Users/mcket747-es/Documents/highschoolData/Fall Spring 2019 Summer 2020 Number 3 .xls")

df2 = pd.read_excel("C:/Users/mcket747-es/Documents/highschoolData/Summer 2019 Number 3.xls")

Merge/Concatenate the dataframes & drop any duplicate roecords

df_merged = pd.concat([df1, df2])
df_merged.drop_duplicates(inplace=True)

'''

Matt
  • 97
  • 10

2 Answers2

0

I think what you need to do is to create a mainloop instead of a one-shot window. Plus you should work with more complicated layout with a button for each operation and their write backend codes to allow user to do several operations like merge, crop etc.

Have a look at PySimpleGUI Cookbook - Persistent Window

alercelik
  • 615
  • 7
  • 11
0

Try this,

import PySimpleGUI as sg

sg.theme('Light Blue 2')

layout = [[sg.Text('Enter 2 files to comare')],
          [sg.Text('File 1', size=(8, 1)), sg.Input(key='Input_1'), sg.FileBrowse()],
          [sg.Text('File 2', size=(8, 1)), sg.Input(key='Input_2'), sg.FileBrowse()],
          [sg.Submit(), sg.Cancel()]]

window = sg.Window('File Compare', layout)

while True:
    event, values = window.read()
    if event in (sg.WINDOW_CLOSED, "Cancel"):
        break
    elif event == 'Submit':
        file_1, file_2 = values['Input_1'], values['Input_2']
        if '' not in [file_1, file_2]:
            # You may need more checks if files exist, if excel files, ...
            # do Excel job here.
            pass

window.close()
Jason Yang
  • 11,284
  • 2
  • 9
  • 23