Parsing the results of askopenfilenames()? Parsing the results of askopenfilenames()? tkinter tkinter

Parsing the results of askopenfilenames()?


This is actually a bug on the Windows version that has been present since around the 2.6 release of Python. You can find the issue on their tracker, and there's a workaround in the comments (I have not personally tried this workaround because I'm on Linux, which returns a proper tuple). I'm not aware of a fix since then, and the issue has not been marked as closed/resolved.

The suggested workaround in the comment is essentially to do this:

master = Tk()files = askopenfilenames(initialdir="C:\\Users\\BVCAP\\Videos", title="Select files")files = master.tk.splitlist(files) #Possible workaroundself.num_files.set(len(files))


When implementing this method today, askopenfilenames returns a tuple of all files chosen, not the strange string with curly braces anymore (must have been fixed).

Oddly, if the cancel button is pressed or the user exits out of the browse window, an empty string is returned instead of an empty list or tuple. Luckily for us Python recognizes strings as iterable objects, meaning you can still check if len(filedialog.askopenfilenames()) == 0.


I don't have an exact answer for you, because I'm still stuck in Python 2.x, but in my world askopenfilenames returns a tuple, so I doubt it would have changed so much going to 3.x. Maybe try casting as a list:

filelist = list(files)

Or using a list comprehension by iterating over it:

filelist = [file for file in files]