I want to create a simple TKinter file selection dialog with a function that I will use from other scripts and not a wider GUI.
My current code is:
# Select a single file and return the full path as a string
def select_file(data_dir):
chdir(data_dir)
root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
return file_path
When I run this the file dialog is always behind other windows. If I have Spyder maximised, it opens behind it so I have to minimise.
There are a few questions related to this, but I've been unable to get any of the suggested code to work, so apologies if this is viewed as a duplicate question.
Ben
Just have to use root.deiconify()
after file_path = tkFileDialog.askopenfilename()
But it's a bad idea to create a new Tk
here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With