tkinter.filedialog ...
asksaveasfile() 与 asksaveasfilename()
askopenfile() 与 askopenfilename()
我什么时候使用一个与另一个?
最佳答案
asksaveasfilename()
和 askopenfilename()
仅返回所选文件的路径作为 str
对象。另一方面,askopenfile()
和 asksaveasfile()
返回一个实际的类文件对象(从技术上讲,一个类型为 _io.TextIOWrapper
的对象) 以后你可以用它来读取或写入。例如:
with tkinter.filedialog.askopenfile() as f:
contents = f.read()
print(contents)
关于python - tkinter.filedialog 打开文件和保存文件的方法。如何选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46718415/