pyqt-选择文件/文件夹

  • 选择文件夹:
    directory = QtWidgets.QFileDialog.getExistingDirectory(self, "getExistingDirectory", "./") 
    #当窗口非继承QtWidgets.QDialog时,self可替换成 None
    
  • 选择文件:
    directory = QtWidgets.QFileDialog.getOpenFileName(self,
                  "getOpenFileName","./",
                  "All Files (*);;Text Files (*.txt)") 
    #当窗口非继承QtWidgets.QDialog时,self可替换成 None
    
  • 选择多个文件
    directory = QtWidgets.QFileDialog.getOpenFileNames(self, self,
                "getOpenFileNames", "./",
                "All Files (*);;Text Files (*.txt)") 
    #当窗口非继承QtWidgets.QDialog时,self可替换成 None
    
  • 设置保存文件名称路径
    directory = QtWidgets.QFileDialog.getSaveFileName(self, 
                  "getSaveFileName","./",
                  "All Files (*);;Text Files (*.txt)") 
    #当窗口非继承QtWidgets.QDialog时,self可替换成 None
    

你可能感兴趣的:(pyqt-选择文件/文件夹)