use*_*771 6 python browser directory file tkinter
我正在用Python做一个小项目,我想浏览一个文件或目录来获取它们的路径.
我正在使用Tkinter,我只能找到一个文件浏览器:
filename = tkFileDialog.askopenfilename(parent=root,title='Open file to encrypt')
Run Code Online (Sandbox Code Playgroud)
或只是一个目录浏览器:
dir = tkFileDialog.askdirectory(parent=root, title='Open file to encrypt')
Run Code Online (Sandbox Code Playgroud)
是否有可能将这两者结合起来?谢谢你的所有答案!
不,不可能将它们组合在一起。文件浏览器和目录浏览器具有不同的UI,因为它们完成不同的任务。
大多数程序通过在“文件”菜单中区分任务来处理此问题。您可能具有“选择文件”或“选择文件夹”选项。这将导致您进入文件浏览器或目录浏览器。