Pyqt5 组件绑定函数传递参数

使用匿名函数进行参数的传递,可以传递多个参数,也可以只传递一个

self.upLoadNewBtn.clicked.connect(lambda: self.upload_dir("new", ))

self.upLoadNewBtn.clicked.connect(lambda: self.upload_dir("new", ))

# 选择文件夹
def upload_dir(self, upload_type):
    dir_path = QFileDialog.getExistingDirectory(None, '选择excel所在文件夹', './', QFileDialog.ShowDirsOnly)
    if not dir_path:
        return
    if not os.path.exists(dir_path):
        return
    if upload_type == "new":
        self.newDirEdit.setText(dir_path)
    elif upload_type == "old":
        self.oldDirEdit.setText(dir_path)

你可能感兴趣的:(PyQt5,qt,python)