Im writing this basic Tk program that can open text documents but i can seem to get it to work
Here is my code:
from Tkinter import *
from tkFileDialog import askopenfilename
def openfile():
filename = askopenfilename(parent=root)
f = open(filename)
x = f.read()
return x
root = Tk()
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=openfile)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
text = Text(root)
text.insert(INSERT,(x))
text.pack()
root.config(menu=menubar)
root.mainloop()
im trying to input x into my tk window but its saying its not defined even though i returned x
why isnt this working im sure its something easy but i cant figure it out!