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 butroot.destroy()
only takes one argument.
This does also work:
button.bind('<Button-1>', lambda event: root_window.destroy())