0
def _error_message(self, message: str):
    self._error_window = tkinter.Toplevel()
    title = tkinter.Label(master = self._error_window,
        text = message, font = DEFAULT)
    title.grid(row = 0, padx = 12, pady = 12, sticky = tkinter.EW)

    ok_error_button = tkinter.Button(master=self._error_window, text='OK',
        font= DEFAULT, command = self._error_window.destroy())
    ok_error_button.grid(row = 1, padx = 10, pady = 10)

    self._error_window.grab_set()

I want to make pressing the "ok" button on a window close a window how do I do that?

1

2 Answers 2

1

Change the name of the button's command to self.destroy Add this before you initialize the button:

def destroy(self)
    self._error_window.destroy()

Good Luck!

Sign up to request clarification or add additional context in comments.

Comments

0
def quit(self):
    self._error_window.destroy()

3 Comments

I may be mistaken (I probably am), but I don't think this will work unless he/she does root = tkinter.Toplevel() instead of top = tkinter.Toplevel() .
Whups, you changed it on me! =)
command =self._close_error_window()) and ......... def _close_error_window(self): and...... self._error_window.destroy()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.