I developed a code at work which I want to make a bit more user friendly to share it with my team. This code requires to know the specific location of the file and code to be in the same folder to run. Long story short, I want to add the option to open a dialog window so they can select the file from any directory. I tried the code below since I want that, right after the file is selected and returns its location, then the Tkinter top window automatically closes without the need of using a button so my team can continue with the next step in the process.
The problem is that the it opens three Tkinter windows and they all remain open after the file is selected.
from tkinter import *
from tkinter import filedialog
top = Toplevel()
root = Tk()
root.fileName = filedialog.askopenfilename(filetypes = (("data migration","*.xlsx"),("data migration","*.csv")))
top.destroy()
top.update()
In addition to aforementioned problems, when I try to close those persisting windows, it shuts down Python.
So far the solutions I've found they all add a button which what I'm trying to avoid if possible.