You want to create a button that closes the GUI application when clicked. Which method should you call inside the command callback?
Trap 1: root.close()
close() is not a method of the Tk object.
Trap 2: root.exit()
exit() is not part of the Tkinter namespace.
Trap 3: root.quit()
quit() stops the mainloop but may not fully destroy the window instance immediately.
- A
root.destroy()
Calling `root.destroy()` terminates the Tkinter main loop and releases all GUI resources, closing the application entirely. This satisfies the stem's requirement that clicking the button closes the whole application, rather than merely hiding a widget or ending a callback. `quit()` would only stop the main loop, leaving the window intact.
- B
root.close()
Why it fails: close() is not a method of the Tk object.
- C
root.exit()
Why it fails: exit() is not part of the Tkinter namespace.
- D
root.quit()
Why it fails: quit() stops the mainloop but may not fully destroy the window instance immediately.