Python TKInter destroy not working Python TKInter destroy not working tkinter tkinter

Python TKInter destroy not working


Do this:

button['command'] = root_window.destroy # give it the function# when the button is pressed the call () is done

Do not do this:

button.bind('<Button-1>', root_window.destroy()) # () makes the call

because

root_window.destroy()

destroys the window before button.bind is called.

This is also wrong: but does not destroy the root window:

button.bind('<Button-1>', root_window.destroy)

because

  • the button can not be triggered with the keyboard
  • root_window.destroy(event) is called but root.destroy() only takes one argument.

This does also work:

button.bind('<Button-1>', lambda event: root_window.destroy())