Python: deleting a TKinter frame

I want to remove a frame from my interface when I click on a specific button.

This is a callback function called

def removeMyself(self):
    del self

However, he does not remove himself. Perhaps I will just delete the object in python without updating the interface?

thank

Update

self.itemFrame = tk.Frame(parent)
self.itemFrame.pack(expand=False, side=tk.TOP)

removeB = tk.Button(self.itemFrame, text="Remove", width=10, command=self.removeIsosurface)

def removeIsosurface(self):
    self.itemFrame.Destroy()

Error message:

AttributeError: Frame instance has no attribute 'Destroy'
+3
source share
4 answers

To delete, call either frm.pack_forget(), or frm.grid_forget()depending on whether the frame was packed or copied.

Then call frm.destroy()if you are not going to use it again, or hold it in the link, and then repack or reload when you want to display it again.

+14
source

del . del something something . something , , , del !!! self - , del self , , , , ( pass).

, . .grid(), .grid_forget(). , - , .grid() ! - .

+3

: self.destroy()

chk this out: PY

0

, . :

  • , ,
  • ( )

, .

from Tkinter import Tk, Frame, Button, Label

class GUI:

    def __init__(self, root):
        self.root = root # root is a passed Tk object
        self.button = Button(self.root, text="Push me", command=self.removethis)
        self.button.pack()
        self.frame = Frame(self.root)
        self.frame.pack()
        self.label = Label(self.frame, text="I'll be destroyed soon!")
        self.label.pack()

    def removethis(self):
        self.frame.destroy()

root = Tk()
window = GUI(root)
root.mainloop()

!

0

Source: https://habr.com/ru/post/1770169/


All Articles