I am making a program with tkinter that will display data from text files into the Text widget. However, when I try to run the program , I receive ' NameError: name 'text_identity' is not defined '. Could anyone explain why this error appears, as well as how it can be fixed?
from tkinter import *
from tkinter import ttk
from tkinter import font
from tkinter.filedialog import askopenfilename
class Manager:
def __init__(self, root):
#The frame for the GUI itself
mainframe = ttk.Frame(root, relief=SUNKEN, padding="3 10 12 12")
mainframe.grid(column=0, row=0, columnspan=10, rowspan=10, sticky="NW")
button_load= ttk.Button(mainframe, text="Load",command=self.OpenFile)
button_load.grid(row=35, column=17, sticky = "NE", padx=5, pady=10)
text_identity = Text(mainframe, width = 15, height = 2)
text_identity.grid(column=8, row=5, sticky=(N,W))
def OpenFile(self):
File1= askopenfilename()
File2= open(File1,'r')
text_identity.insert("1.0",File2.read())
File2.close()
def main():
root = Tk()
Manager(root)
root.title("Data Management")
root.mainloop()
if __name__ == main():
main()