本文介紹了Python FileDialog獲取文件夾路徑不是文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 Python 3.6.我也使用 PyQt.我使用 Qt Designer 開發表單.但我需要一個代碼來打開一個文件對話框,允許用戶導航到所需的文件夾(不是文件),然后單擊并打印/獲取文件夾路徑.我找不到如何做到這一點.我在這里感謝任何人的幫助.謝謝.
I am using Python 3.6. I also use PyQt. I use Qt Designer to develop a form. But I need a code to open a filedialog box, allow the user to navigate to the desired FOLDER (not file) and then click and print/get the folderpath. I cannot find how to do this. I appreciate anyone's help here. Thanks.
推薦答案
您可以通過應用必要的過濾器來使用 QFileDialog
的 getExistingDirectory()
方法:
You can use the getExistingDirectory()
method of QFileDialog
by applying the necessary filters:
import sys
from PyQt5 import QtWidgets, QtCore
app = QtWidgets.QApplication(sys.argv)
directory = QtWidgets.QFileDialog.getExistingDirectory(None,
"Select Directory",
QtCore.QDir.currentPath())
print(directory)
這篇關于Python FileDialog獲取文件夾路徑不是文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!