class CloseAfterFinishFrame2(tk.Frame):

    def __init__(self, master):
        tk.Frame.__init__(self, master)
tk.Label(self, text='Hey', font=('Arial', 16)).pack()
button = tk.Button(self, text='the End', command=self.CloseWindow, font=(
    'Arial', 12))
button.pack()
self.pack()

def CloseWindow(self):
    root.quit()
root = tk.Tk()
CloseAfterFinishFrame1(root)
root.mainloop()
выйти из основного цикла в python