python - 我想将“文件名”作为参数传递给其他函数调用,但总是返回“无”作为值
问题描述
我正在使用 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 时,它会将打印输出显示为“无”,并且从函数的定义中它会在函数调用中获取文件名,但它没有返回任何值。有人可以提出可能的原因吗?我想将“文件名”作为参数传递给其他函数调用,但它总是返回“无”作为值。
解决方案
你有没有尝试过
return QtGui.QFileDialog.getOpenFileName(mainwindow, 'Select file')
您可以将名称文件名设为全局。
def fileopening():
global filename
filename = QtGui.QFileDialog.getOpenFileName(mainwindow, 'Select file')
推荐阅读
- c# - 可以通过移动物体看到镜头光晕吗?
- hibernate - JPA:命名查询数据库独立性
- c# - 当我尝试访问实体组件数据时,当我构建到我的 Iphone 时,Unity c# null 引用错误
- python - 是否有用于身份管理的 Microsoft Azure Ansible 模块?
- mongodb - 从异步 mongo.save() 获取空对象
- c# - 是否有将选中复选框的数量保存在变量中的功能?
- python - 名称上带有空格的 Jupyter Notebook 文件夹给出 [Errno 2] 使用“另存为”时没有此类文件或目录
- python - 如何在 Python 中使用 Spotify API 播放播放列表?
- javascript - 在对象数组中搜索不区分大小写的部分匹配并按字母顺序对结果进行排序
- python - 如何使两个Lists对应并创建一个deck