tkinter界面失去响应无法关闭问题

用tkinter编写的界面,运行时有时候正常,有时候失去响应,而且失去响应后无法关闭,最后每次只能强制关机,重新启动电脑。
程序中有两个for循环嵌套。
怎么能避免它偶发性的失去响应?
有没有哪位能帮忙解决一下

img

mainloop()有没有用,以下实例参考:

import tkinter as tk

class HelloWorld(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.entry = tk.Entry(self)
        self.button = tk.Button(self, text="What's your input?", command=self.on_button)
        self.button.pack()
        self.entry.pack()

    def on_button(self):
        answer = self.entry.get()
        if answer == "a":
            print("Hello World")
        elif answer == "b":
            print("Hello World 2")
        elif answer == "c":
            root.destroy()

root = HelloWorld()
root.mainloop()

我觉得是需要多线程的缘故。