python Tkinter tkFileDialog [英] python Tkinter tkFileDialog

查看:19
本文介绍了python Tkinter tkFileDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,有什么区别

tkFileDialog.asksaveasfile

tkFileDialog.asksaveasfilename

我无法从文档中的构建中理解

I could not understand from the build in docs

推荐答案

asksaveasfile 要求用户提供一个文件,然后以写入模式打开该文件并将其返回给您,以便您可以在其中写入.

asksaveasfile asks the user for a file, then opens that file in write mode and returns it to you so you can write in it.

asksaveasfilename 向用户询问文件,然后返回该文件的名称.没有打开文件;如果你想写入文件,你必须自己打开它.

asksaveasfilename asks the user for a file, then returns that file's name. No file is opened; if you want to write to the file, you'll have to open it yourself.

asksaveasfilename 可能比 asksaveasfile 更受欢迎,如果你想对文件做一些更有趣的事情,而不仅仅是向它写入数据.例如,您可能希望首先将文件复制到另一个目录作为备份.在这种情况下,您希望只获取文件名,以便您可以执行复制,而不必担心打开文件是否会导致复制失败.

asksaveasfilename might be preferred over asksaveasfile if you want to do something fancier to the file than just writing data to it. For instance, you might want to first copy the file to another directory as a backup. In which case, you'd prefer to get just the file name so you can perform the copy without having to worry about whether having the file open will cause the copy to fail.

这篇关于python Tkinter tkFileDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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