Create an Advanced GUI App With PySimpleGUI
A PySimpleGUI app that converts an Excel file to CSV, built up feature by feature: a browse dialog limited to Excel files, a preview of the sheet, checks that the paths exist, settings saved in a config.ini file, a custom menu bar, and finally a standalone .exe.
Update (November 2026): PySimpleGUI is open source again under the LGPL, and pip install PySimpleGUI now installs version 6; pip install PySimpleGUI==4.60.5.1 installs the release this tutorial was recorded with.
Table of contents

First layout
Install PySimpleGUI with pip install pysimplegui and import it as sg. A layout is a list of rows, and each row is a list of elements: here a file input with a browse button, a folder input with a browse button, and a row with the Exit and Convert buttons.
import PySimpleGUI as sg # pip install pysimplegui
# ------ GUI Definition ------ #
layout = [
[sg.Text("Input File:"), sg.Input(key="-IN-"), sg.FileBrowse()],
[sg.Text("Output Folder:"), sg.Input(key="-OUT-"), sg.FolderBrowse()],
[sg.Exit(), sg.Button("Convert To CSV")],
]
Excel files only
The file_types parameter of FileBrowse limits what the dialog shows. It takes a tuple of (label, pattern) pairs, and the pattern *.xls* matches .xls, .xlsx and .xlsm files. The event loop below opens the window and closes it on Exit.
import PySimpleGUI as sg # pip install pysimplegui
# ------ GUI Definition ------ #
layout = [
[sg.Text("Input File:"), sg.Input(key="-IN-"), sg.FileBrowse(file_types=(("Excel Files", "*.xls*"),))],
[sg.Text("Output Folder:"), sg.Input(key="-OUT-"), sg.FolderBrowse()],
[sg.Exit(), sg.Button("Convert To CSV")],
]
window = sg.Window("Excel 2 CSV Converter", layout)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, "Exit"):
break
if event == "Convert To CSV":
sg.popup_error("Not yet implemented")
window.close()
Convert to CSV
pandas does the conversion: read_excel loads the sheet and to_csv writes it with the separator and decimal symbol you choose. Install it with pip install pandas openpyxl, because pandas needs openpyxl to read .xlsx files.
The convert_to_csv function names the CSV after the Excel file and saves it in the output folder. For the opposite direction, many text or CSV files into one workbook, see converting CSV files to Excel with Python.
from pathlib import Path # core python module
import pandas as pd # pip install pandas openpyxl
import PySimpleGUI as sg # pip install pysimplegui
def convert_to_csv(excel_file_path, output_folder, sheet_name, separator, decimal):
df = pd.read_excel(excel_file_path, sheet_name)
filename = Path(excel_file_path).stem
outputfile = Path(output_folder) / f"{filename}.csv"
df.to_csv(outputfile, sep=separator, decimal=decimal, index=False)
sg.popup_no_titlebar("Done! :)")
# ------ GUI Definition ------ #
layout = [[sg.Text("Input File:"), sg.Input(key="-IN-"), sg.FileBrowse(file_types=(("Excel Files", "*.xls*"),))],
[sg.Text("Output Folder:"), sg.Input(key="-OUT-"), sg.FolderBrowse()],
[sg.Exit(), sg.Button("Convert To CSV")],]
window = sg.Window("Excel 2 CSV Converter", layout)
Preview the sheet
A Display Excel File button lets the user check the data before converting it. It opens a scrollable popup with the data type of each column, a separator line and the rows of the sheet.
def display_excel_file(excel_file_path, sheet_name):
df = pd.read_excel(excel_file_path, sheet_name)
filename = Path(excel_file_path).name
sg.popup_scrolled(df.dtypes, "=" * 50, df, title=filename)

Validate the paths
Without a check, an empty or wrong path crashes the app. is_valid_path returns True only when the path is filled in and exists; otherwise it shows an error popup. The app calls it before the preview and before every conversion.
def is_valid_path(filepath):
if filepath and Path(filepath).exists():
return True
sg.popup_error("Filepath not correct")
return False
Settings file
A config.ini file next to the script holds everything a user might want to change: the window title, font, font size and theme, the CSV separator and decimal symbol, and the sheet name to read. PySimpleGUI’s UserSettings reads and writes it in ini format.
[GUI]
title = Excel 2 CSV Converter
font_size = 14
font_family = Arial
theme = DarkTeal10
[CSV]
separator = |
decimal = .|,
decimal_default = ,
[EXCEL]
sheet_name = Sheet1
At startup the script loads the file and applies the theme and font before it opens the main window:
if __name__ == "__main__":
SETTINGS_PATH = Path.cwd()
# create the settings object and use ini format
settings = sg.UserSettings(
path=SETTINGS_PATH, filename="config.ini", use_config_file=True, convert_bools_and_none=True
)
theme = settings["GUI"]["theme"]
font_family = settings["GUI"]["font_family"]
font_size = int(settings["GUI"]["font_size"])
sg.theme(theme)
sg.set_options(font=(font_family, font_size))
main_window()
Settings window
The Settings button opens a modal window with the current separator, decimal symbol and sheet name. Save Current Settings writes the new values straight back into config.ini, so they are still there the next time the app starts.
def settings_window(settings):
# ------ GUI Definition ------ #
layout = [[sg.T("SETTINGS")],
[sg.T("Separator"), sg.I(settings["CSV"]["separator"], s=1, key="-SEPARATOR-"),
sg.T("Decimal"), sg.Combo(settings["CSV"]["decimal"].split("|"),
default_value=settings["CSV"]["decimal_default"],
s=1, key="-DECIMAL-"),
sg.T("Sheet Name:"), sg.I(settings["EXCEL"]["sheet_name"], s=20, key="-SHEET_NAME-")],
[sg.B("Save Current Settings", s=20)]]
window = sg.Window("Settings Window", layout, modal=True, use_custom_titlebar=True)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
if event == "Save Current Settings":
# Write to ini file
settings["CSV"]["separator"] = values["-SEPARATOR-"]
settings["CSV"]["decimal_default"] = values["-DECIMAL-"]
settings["EXCEL"]["sheet_name"] = values["-SHEET_NAME-"]
# Display success message & close window
sg.popup_no_titlebar("Settings saved!")
break
window.close()
Menu bar and styling
sg.MenubarCustom adds a menu bar that follows the theme colors, with a Toolbar menu and a Help menu holding Settings, About and Exit. Each menu entry arrives in the event loop as an event with its name, just like a button.
The final main window also uses the short element names (sg.T, sg.I, sg.B), fixed sizes for labels and buttons, a red Exit button and a custom title bar. About hides the main window while its popup is open. If all you need is one question to the user, such as a folder or a file, the one-line PySimpleGUI popups are enough.
def main_window():
# ------ Menu Definition ------ #
menu_def = [["Toolbar", ["Command 1", "Command 2", "---", "Command 3", "Command 4"]],
["Help", ["Settings", "About", "Exit"]]]
# ------ GUI Definition ------ #
layout = [[sg.MenubarCustom(menu_def, tearoff=False)],
[sg.T("Input File:", s=15, justification="r"), sg.I(key="-IN-"), sg.FileBrowse(file_types=(("Excel Files", "*.xls*"),))],
[sg.T("Output Folder:", s=15, justification="r"), sg.I(key="-OUT-"), sg.FolderBrowse()],
[sg.Exit(s=16, button_color="tomato"), sg.B("Settings", s=16), sg.B("Display Excel File", s=16), sg.B("Convert To CSV", s=16)],]
window_title = settings["GUI"]["title"]
window = sg.Window(window_title, layout, use_custom_titlebar=True)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, "Exit"):
break
if event == "About":
window.disappear()
sg.popup(window_title, "Version 1.0", "Convert Excel files to CSV", grab_anywhere=True)
window.reappear()
if event in ("Command 1", "Command 2", "Command 3", "Command 4"):
sg.popup_error("Not yet implemented")
if event == "Display Excel File":
if is_valid_path(values["-IN-"]):
display_excel_file(values["-IN-"], settings["EXCEL"]["sheet_name"])
if event == "Settings":
settings_window(settings)
if event == "Convert To CSV":
if (is_valid_path(values["-IN-"])) and (is_valid_path(values["-OUT-"])):
convert_to_csv(
excel_file_path=values["-IN-"],
output_folder=values["-OUT-"],
sheet_name=settings["EXCEL"]["sheet_name"],
separator=settings["CSV"]["separator"],
decimal=settings["CSV"]["decimal_default"],
)
window.close()
Build an executable
psgcompiler turns the script into a .exe that runs on computers without Python. Install it in a fresh virtual environment that contains only PySimpleGUI, pandas and openpyxl, because every package in the environment can end up in the executable and make it larger.
Start psgcompiler, select main.py and convert. The .exe lands in the project folder. Keep config.ini next to it, because the app reads its settings from the current folder.

