QtWidgets.QFileDialog.getOpenFileName returns a Tuple(QtWidgets.QFileDialog.getOpenFileName 返回一个元组)
问题描述
我最近更新到了 Qt5 for Python 的新版本.在这样做的过程中,我不得不根据已经发生的一些显着变化来更改我的代码.我想深入了解我创建的这行代码.这感觉像是一种解决从函数中获取 string
而不是 tuple
问题的肮脏方式.(注意行尾的[0]
)
I've recently updated to the new version of Qt5 for Python. In doing so, I've been having to alter my code in accordance to some of the notable changes that have occurred. I wanted to get some insight into this line of code that I've created. It feels like a dirty way of solving the problem of getting a string
instead of a tuple
from the function. (Note the [0]
at the end of the line)
filename = QtWidgets.QFileDialog.getOpenFileName(None, "Open " + key + " Data File", '.', "(*.csv)")[0]
我想要 filename = {str}'C:/.././.../format.csv'
not filename = <class 'tuple'>: ('C:/.././.../format.csv', '(*.csv)')
推荐答案
在查看了一个也正在更新到 Qt5 的存储库之后;我发现他们使用了这样的一行.
After looking through a repository that was being updated to Qt5 as well; I found they used a line like this.
filename, _filter = QtWidgets.QFileDialog.getOpenFileName(None, "Open " + key + " Data File", '.', "(*.csv)")
filename
是一个字符串,并且 (*.csv) 在 _filter
变量中被丢弃
filename
is a string and the (*.csv) gets discarded in the _filter
variable
这篇关于QtWidgets.QFileDialog.getOpenFileName 返回一个元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:QtWidgets.QFileDialog.getOpenFileName 返回一个元组


基础教程推荐
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01