I am trying to create a GUI in Python that searches a directory and brings back matches. However, whenever I run it I get the error 'NoneType' object has no attribute 'insert' for the textfield insert part. What am I doing wrong?
from tkinter import *
root = Tk()
root.title("ICD-10-CM Lookup")
ICD_10_CM = StringVar()
label1 = Label(root, text="ICD-10_CM Code").grid(row=0, column=0)
query = Entry(root, textvariable=ICD_10_CM).grid(row=0, column=1)
def search():
infile = open("icd10cm.txt", "r")
for line in infile:
line = line.strip()
elements = line.split("\t")
if str(query) in elements[0]:
textfield.insert(elements[1])
elif str(query) in elements[1]:
textfield.insert(elements[0])
infile.close()
search_button = Button(root, text="Search", command=search).grid(row=2,column=0)
textfield = Text(root).grid(row=1,column=1,rowspan=2)
root.mainloop()