Parsing the results of askopenfilenames()?

前端 未结 4 629
耶瑟儿~
耶瑟儿~ 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 07:13

    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 workaround
    self.num_files.set(len(files))
    

提交回复
热议问题