完整代码如下:
from PySide2.QtWidgets import QFileDialog, QDialog, QApplication, QMainWindow
class DlgSelectMp3(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
def selectMp3s(self):
fileNames = []
fileDialog = QFileDialog(self)
fileDialog.setViewMode(QFileDialog.Detail)
fileDialog.setFileMode(QFileDialog.ExistingFiles)
fileDialog.setNameFilter("python file(*.mp3);;all file(*)")
ret = fileDialog.exec_()
if ret == QDialog.Accepted:
fileNames = fileDialog.selectedFiles()
return fileNames
if __name__ == "__main__":
app = QApplication([])
dlgmw = DlgSelectMp3()
selectFiles = dlgmw.selectMp3s()
for it in selectFiles:
print(it)
app.exec_()
更多python代码,可以去这里看看: