Hello. I'm learning tkinter and trying out the opening file bit and im obviously doing something wrong.

def init_window(self):  
    self.txt = Text(self)
    self.txt.pack(fill=BOTH, expand=1)

def open_file(self):
    filetypes = [('All files', '*')]
    dialog = filedialog.Open(self, filetypes=filetypes)
    showD = dialog.show()

    if showD!= '':
        text = self.readFile(showD)
        self.txt.insert(END, txt)

def readFile(self, filename):
    with open(filename, 'r') as f:
        text = f.read()
    return text

at self.txt.insert(END, txt), command prompt says txt isn't defined but python reads line by line doesn't self.txt = Text(self) in init_window function define txt? what am i missing here?

I'm reading line 11 where you put content into the variable "text" and line 12 where you call out "txt". To me this looks incorrect. I might be wrong.