简体   繁体   English

getSaveFileName,getOpenFileName向我显示要保存或打开的文件,但无法保存该文件或在python QT中打开该文件

[英]getSaveFileName , getOpenFileName shows me the file to save or open, but cannot save the file or open the file in python QT

1.fileName = QtGui.QFileDialog.getOpenFileName(self, "Open File",
                        "F:/python/bc_new_latest/bcForecasting.csv",
                        "Excel (*.csv *.xls )");

2.fileName = QtGui.QFileDialog.getSaveFileName(self, "Save",
                        "F:/python/bc_new_latest/bcForecasting.csv",
                        "Excel (*.csv *.xls )");

The above 2 codes shows me file dialog's to open me the file in specified location or save the file. 上面的2个代码向我显示了文件对话框,用于在指定位置打开文件或保存文件。 But can not open the file or save the file in different location. 但是无法打开文件或将文件保存在其他位置。 What code I have to add here. 我必须在这里添加什么代码。 Thanks in advance 提前致谢

These functions only allow the user to select files, they don't actually open or save the files. 这些功能仅允许用户选择文件,而实际上并未打开或保存文件。

In PySide, they return a tuple, so for example, saving the file would look like this: 在PySide中,它们返回一个元组,因此,例如,保存文件将如下所示:

fileName, selectedFilter = QtGui.QFileDialog.getSaveFileName(self, "Save",
                    "F:/python/bc_new_latest/bcForecasting.csv",
                    "Excel (*.csv *.xls )")
if fileName:
   with open(fileName, "w") as file:
       file.write(theCSVContent)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM