It seems like you are calling the save()
method before calling the askopenfilename()
method. That's why, you get the AttributeError
. Make sure the flow of your code reflects this change.
You might also want to include proper error handling in your askopenfilename()
method itself to include situations where no file is opened.
You could do something on these lines. First initialize the self.filename = None
in your constructor for the MainWindow
class. Then you could modify your method as such:
def askopenfilename(self):
self.filename = tkFileDialog.askopenfilename(filetypes=[("Text Files",'.txt')])
if not self.filename: return None
return self.filename.name
However this is just to give you an idea, I have not myself worked with Tkinter
much. All in all, it would depend on what exactly you are trying to achieve.