尝试使用PyQt5 QFileDialog设置setText到textEdit小部件的目录路径

时间:2019-06-20 19:23:49

标签: python macos pyqt5

我正在MacOS上使用PyQt5和Python编写程序,该程序将在多个硬盘驱动器上创建一个文件夹结构。当单击按钮打开文件时,下面的代码将打开文件浏览器。我想要它允许您选择将在其中创建文件夹的目录。然后将文件夹路径(例如“ / Volumes / 24TB_RAID / JOBS”)存储在textEdit中,然后在单击“创建”按钮时创建文件夹。

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QFileDialog
from PyQt5.uic import loadUi

def openFileNameDialog(self):
    options = QFileDialog.Options()
    options |= QFileDialog.DontUseNativeDialog
    fileName, _ = QFileDialog.getOpenFileName(self, 
"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
    if fileName:
        print(fileName)

def clicked_raid_drive(self):
    return openFileNameDialog(self)

#-------------------------------------------------------
class MyWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        loadUi('File-Structure.ui', self)
        self.setWindowTitle('File-Structure')

        self.RaidDriveBtn.clicked.connect(lambda: clicked_raid_drive(self))

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())

0 个答案:

没有答案