Skip to content
Advertisement

Tkinter quit freezes

I have written a very simple snippet of code just to try tkinter:

import tkinter as tk

root=tk.Tk()
frame = tk.Frame(root).pack()
button = tk.Button(frame,
                   text="next",
                   command=root.quit).pack()
root.mainloop()

The above code causes the window to freeze. Could someone explain to me what is the reason behind this behaviour?

Advertisement

Answer

Seperating the pack() from the initialisation lines will fix your issue.

import tkinter as tk
root=tk.Tk()
frame=tk.Frame(root)
frame.pack()
button = tk.Button(frame,text="next",command=root.quit)
button.pack()
root.mainloop()
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement