Python: removing a TKinter frame

前端 未结 4 1160
走了就别回头了
走了就别回头了 2021-02-06 07:35

I want to remove a frame from my interface when a specific button is clicked.

This is the invoked callback function

def removeMyself(self):
    del self
         


        
4条回答
  •  抹茶落季
    2021-02-06 08:21

    del does not delete anything. del something just removes something from the local scope. And although if something was the only reference to an object, it may allow the object it to be garbage collected in the future, don't even think of using del to delete objects!!! And since self is just a normal variables, del self does nothing, except of course stopping the rest of the method from accessing the instance (so at the end of the method, it's actually like pass).

    The exact way to remove a widget from the GUI depends on what geometry manager you use. If you used .grid(), you can use .grid_forget(). Note that this still doesn't destroy the widget - quite the contrary, you can go on and .grid() it again! - but that doesn't make any difference.

提交回复
热议问题