How would I make destroy() method in tkinter work with my code? How would I make destroy() method in tkinter work with my code? tkinter tkinter

How would I make destroy() method in tkinter work with my code?


GameBoard()

creates a new instance of GameBoard. Therefore:

GameBoard().destroy()

creates a new instance and calls destroy() on it which has no effect on the existing instance.

You want access the current instance in your _close() method which is done through self:

def _close(self):    self.destroy()

However, this only destroys the frame (and its child windows, like the button), not the top level window (master).

To completely close the UI, you could call self.master.destroy() or simply self.quit():

def _close(self):    self.quit()


self.master.destroy() will close both the parent and child process (see I.E. for example). self.destroy will close the child process. I know this is an old post, but I figured this information might still be applicable to someone.

I.E.

def _close(self):    self.master.destroy()