I'd like to store a file. For this reason, I use filedialog with a 'with' statement. As long as I chose a file and save it, everything works fine. However, when the filedialog is canceled, I get the following error:
File "...\src\test.py", line 7, in with filedialog.asksaveasfile(mode='w') as myFile: AttributeError: enter
Is there a work arround to accomplish this with the 'with' statement?
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
with filedialog.asksaveasfile(mode='w') as myFile:
myFile.write('Test')
root.mainloop()