You aren't actually destroying anything in your function. Look at this code:
def main2(root,self):
self.destroy
app = MainGameUI(root)
root.mainloop()
Notice the first line in the function where you are trying to destroy everything. Your code is self.destroy
- notice the lack of parenthesis. You aren't actually calling the function, you are simply referencing it. Add parentheses to call it: self.destroy()
.
You have another problem in that you're calling a function that destroys the widget that calls the function. However, this function enters into an endless loop (mainloop()
), so the button command will never return. I'm not entirely sure what will happen here, you'll probably get some sort of error. The bottom line is, calling mainloop
from a button command is not a good idea.
Since you are structuring your app such that the app is a frame (rather than the root window) you don't need to restart the event loop. When you destroy the MainMenuUI
widget, the event loop will continue to run. There's no need to restart it.