Python tkFileDialog.asksaveasfile - get file path

不羁岁月 提交于 2019-12-11 04:18:57

问题


I want to get path of file "exportFile".

exportFile = tkFileDialog.asksaveasfile(mode='a')

If I write "print exportFile", I get:

<open file u'C:/Users/Desktop/Test/aaaa.txt', mode 'a' at 0x02CB6078>

But I need only path - "C:/Users/Desktop/Test/aaaa.txt". Is there any solution? Thank you.


回答1:


Use tkFileDialog.asksaveasfilename instead of tkFileDialog.asksaveasfile.

NOTE tkFileDialog.asksaveasfilename does not take mode parameter.




回答2:


Try this:

exportFile = tkFileDialog.asksaveasfile(mode='a')
exportFile.name

It'll return:

'C:/Users/Desktop/Test/aaaa.txt'



回答3:


Try tkFileDialog.askdirectory instead of any file name dialog. That will return a directory instead of a file name.



来源:https://stackoverflow.com/questions/21877216/python-tkfiledialog-asksaveasfile-get-file-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!