I'm working on building a simple, little text editor but I'm getting an error back that I just can't figure out. It has to do with my use of the .get() function in Tkinter. I'm using python2.7. Can anyone help? Below is the code:
from Tkinter import *
def open_file():
user_file = open(user_input.get(), 'a')
file_contents = user_file.read()
text_box.insert(END, file_contents)
root = Tk()
user_input = Entry(root).pack(side=TOP)
text_box = Text(root).pack()
b1 = Button(root, text="open", command=open_file).pack(side=LEFT)
b2 = Button(root, text="save").pack(side=LEFT)
b3 = Button(root, text="quit", command=root.quit).pack(side=LEFT)
root.mainloop()
The error message reads:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
return self.func(*args)
File "/home/brandon/TkProjects/TextEditor.py", line 7, in open_file
user_file = open(user_input.get, 'a')
AttributeError: 'NoneType' object has no attribute 'get'
Which says that I don't have the attribute .get() but I don't understand why. I've created an Entry widget named user_input. I tried storing it in a variable but that didn't work either. Please help.
filename = user_input.get()