tkinter.filedialog open file and savefile methods . How to choose?
asksaveasfilename()
and askopenfilename()
return only the path to the selected file as a str
object. On the other hand, askopenfile()
and asksaveasfile()
return an actual file-like object (technically, an object of type _io.TextIOWrapper
) which you can use to read from or write to later on. For instance:
with tkinter.filedialog.askopenfile() as f: contents = f.read() print(contents)