I'm making a coding language in python and I want people to be able to save their code in a file with their own file name.
I've tried coding it but it keeps coming up with the error:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Here is my current code:
import os
root = Tk()
def save_name():
global file_title
save_namewindow = Toplevel(root)
save_namewindow.title("Save")
Label(save_namewindow, text="Name the File").pack()
file_title = Entry(save_namewindow).pack()
Button(save_namewindow, text="Save", command=save).pack()
def save():
file_name = (file_title + ".txt")
if os.path.isfile(file_name):
if messagebox.askyesno("File Exists", "Would you like to overwrite the existing file '" + file_name + "'?"):
os.remove(file_name)
file = open(file_name, "x")
file.write(shell.get("1.0", END))
file.close()
else:
file = open(file_name, "x")
file.write(shell.get("1.0", END))
file.close()
I want the answer to be: file_name = file_title + '.txt'
in the correct way.
Thanks in advance.