Parsing the results of askopenfilenames()?

前端 未结 4 640
耶瑟儿~
耶瑟儿~ 2020-12-06 06:46

I\'m trying to get a list of filenames from tkinter.filedialog.askopenfilenames() in Python 3.2.

    files = askopenfilenames(initialdir=\"C:\\\\Users\\\\BVC         


        
4条回答
  •  旧巷少年郎
    2020-12-06 06:51

    I support Eldererathis's answer as the best solution I have found for Python versions 2.X (mainly 2.5 and above) versions under Linux, Mac OS X and Windows. When a tkFileDialog calls the askopenfilename(...,multiple=1) methods with argument multiple=1, I could not get it work properly under Windows (Linux and Mac OS X were fine) when a single file was selected (the file is processed as a 'str' instead of a 'tuple').

    I tried the files = re.findall('\{(.*?)\}', files suggested by Paul in the comments, but it did not change anything. I also tried files = tuple(files) and files = list(files), but it is not a viable workaround from what I have seen.

    So far, files = tkRoot.master.splitlist(files) is what is working under all environments I have tested (Win32, Win64, Linux32, Linux64, Mac OS X).

提交回复
热议问题