pyQt5-文件选择框

# -*- coding:utf-8 -*-
"""
@Time:2022/3/30 20:59
@Author:小柠檬
@File:file_dialog.py
"""
from PyQt5 import uic, QtCore
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QFileDialog

ICO_PATH = r'F:\pyDemo\other\07-gui_Qt5\02-控件\00-resource\ico\xnm.ico'


class FileDialog:

    def __init__(self):
        # 加载UI界面
        self.ui = uic.loadUi("file_dialog.ui")

        # 信号和槽关联
        self.ui.pushButton_folder.clicked.connect(self.slot_folder)
        self.ui.pushButton_file.clicked.connect(self.slot_file)

    def slot_folder(self):
        # 选择文件夹槽
        folder_path = QFileDialog.getExistingDirectory(self.ui, "选择文件夹")
        print(folder_path)

    def slot_file(self):
        # 选择文件槽
        file_path, _ = QFileDialog.getOpenFileName(self.ui, "选择文件")  # 选择单个文件
        print(file_path)

        # file_paths, _ = QFileDialog.getOpenFileNames(self.ui, "选择多个文件")  # 选择多个文件
        # print(file_paths)
        

def main():
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)  # 和designer设计的窗口比例一致
    app = QApplication([])
    app.setWindowIcon(QIcon(ICO_PATH))
    file_dialog = FileDialog()
    file_dialog.ui.show()
    app.exec_()


if __name__ == '__main__':
    main()


你可能感兴趣的:(pyQt5,qt5,python)