在Python浏览文件或目录对话框 [英] Browsing file or directory Dialog in Python

查看:1139
本文介绍了在Python浏览文件或目录对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做Python中的小项目,我想浏览一个文件或目录,以得到他们的路径。

I'm doing a small project in Python and I would like to browse a file or directory to get their path.

我使用Tkinter的,我是abble只找到一个文件浏览器:

I'm using Tkinter and I was abble to find only a file browser:

filename = tkFileDialog.askopenfilename(parent=root,title='Open file to encrypt')

或者只有目录浏览器:

or only a directory browser:

dir =  tkFileDialog.askdirectory(parent=root, title='Open file to encrypt')

是否有可能这两个结合起来?
感谢您对所有的答案!

Is it possible to combine these two? THank you for all the answers!

推荐答案

没有,这是不可能把它们结合起来。文件浏览器和目录浏览器有不同的用户界面,因为它们正在完成不同的任务。

No, it's not possible to combine them. The file browser and directory browser have different UIs because they are accomplishing different tasks.

大部分程序在他们的文件菜单区分任务处理这个问题。你可能有一个选择文件或选择文件夹选项。这将导致你要么文件浏览器或目录浏览器。

Most programs handle this by differentiating the task in their File menu. You might have a "Select File" or "Select Folder" option. This would lead you to either the File browser or the Directory browser.

这篇关于在Python浏览文件或目录对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆