The problem is that your code for closing the file and displaying the longest line is never executed:
while 1:
rd = txtFile.readline()
if len(rd)> x:
longest = rd
x = len(rd)
elif rd == '':
break
txtFile.close()
entr.delete(0, END)
entr.insert(0, longest)
break
breaks out of the while-loop, and as there is no more code after it, Python returns from the function. Move the last three lines out of the while
-loop and you should be good:
# Using 'True' for infinite loops is more idiomatic/pythonic
while True:
rd = txtFile.readline()
if len(rd) > x:
longest = rd
x = len(rd)
elif rd == '':
break
txtFile.close()
entr.delete(0, END)
entr.insert(0, longest)