You can call pack_forget
to remove a widget (if you use pack
to add it to the window).
Example:
from tkinter import *
root = Tk()
b = Button(root, text="Delete me", command=lambda: b.pack_forget())
b.pack()
root.mainloop()
If you use pack_forget
, you can later show the widget again calling pack
again. If you want to permanently delete it, call destroy
on the widget (then you won't be able to re-add it).
If you use the grid
method, you can use grid_forget
or grid_remove
to hide the widget.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…