Python 如何有一个目录对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4286036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 15:04:27 来源:igfitidea点击:
how to have a directory dialog
提问by Moayyad Yaghi
In PyQt, how does one display a file browser that shows and selects only directories (not files)?
在 PyQt 中,如何显示仅显示和选择目录(而不是文件)的文件浏览器?
And how does one retrieve the name of the selected directory?
以及如何检索所选目录的名称?
采纳答案by TZHX
From inside your QDialog/QWidget class, you should be able to do:
从您的 QDialog/QWidget 类内部,您应该能够执行以下操作:
file = str(QFileDialog.getExistingDirectory(self, "Select Directory"))

