I am trying to open new file but want to check if there is something in the current file before opening a new file so it can be saved. I have the following if statements.
Thanks.
global open_status_name
open_status_name = False
def new_file():
global open_status_name
#first statement checking if there is file name and the textbox is not empty, this will Triger save function
if open_status_name and len(my_text.get(1.0,END)) != 0:
save_file()
#second statement checking if there is no file name and the textbox is not empty, this will Triger save as function
elif (open_status_name == False) and (len(my_text.get(1.0,END)) != 0):
save_as_file()
#last statement checking if there is no file name and the textbox is empty, this will Triger new file function
elif (open_status_name == False) and (len(my_text.get(1.0,END)) == 0):
return
my_text.delete("1.0", END)
root.title('New File')
status_bar.config(text="New File ")
open_status_name = Falseopen_status_nameis false as it doesn't hold a file name (the file is new at the start of the program but it will change while the program is running). for the if statements i am checking if there is a file name and if the file is empty or not. When I am opening new file and the current file is empty it is going for save as but it should go for a new file without saving as there is nothing there.
Thanks.
