我想将 'Filename' 作为参数传递给其他函数调用,但它总是返回 'None' 作为值

I want to pass 'Filename' as argument to other function call but always it is returning 'None' as value

我正在使用 PyQT4 开发 GUI:代码如下所示 -

def fileopening(): 
    filename = QtGui.QFileDialog.getOpenFileName(mainwindow, 'Select file') 
    print(filename) 
    return filename


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    mainwindow = QtGui.QWidget()
    ui = Ui_mainwindow()
    ui.setupUi(mainwindow)
    filename = ui.browser.clicked.connect(fileopening)
    print(filename)
    ui.progressBar.setValue(100)
    ui.progesslabel.setText('Kindly fill in the fields and proceed for splitting.')
    ui.splitbutton.clicked.connect(pressed)
    ui.resetparameter.clicked.connect(reset)

    mainwindow.show()
    app.exec_()

当提示 UI 时,它给出的打印输出为 'None' 并且根据函数的定义,它在函数调用中获取文件名,但它不返回任何值。有人可以提出可能的原因吗?我想将 'Filename' 作为参数传递给其他函数调用,但它总是返回 'None' 作为值。

你试过了吗

return QtGui.QFileDialog.getOpenFileName(mainwindow, 'Select file')

您可以将文件名设为全局名称。

def fileopening(): 
    global filename
    filename = QtGui.QFileDialog.getOpenFileName(mainwindow, 'Select file')