QtWidgets.QFileDialog.getOpenFileName返回一个元组 [英] QtWidgets.QFileDialog.getOpenFileName returns a Tuple

查看:1368
本文介绍了QtWidgets.QFileDialog.getOpenFileName返回一个元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近已更新到适用于Python的Qt5的新版本.为此,我不得不根据已经发生的一些显着更改来更改代码.我想对我创建的这一行代码有所了解.感觉像是一种从方法中获取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'

不是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返回一个元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆