tkinter.filedialog ...
asksaveasfile() vs asksaveasfilename()
askopenfile() vs askopenfilename()
when would I use one vs the other?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With