Does anybody know how to clear all widgets; labels, buttons, etc. from a tkinter frame so that new ones may be put in their place? I've tried self.destroy() but that makes the frame unreachable, and self.grid_forget() followed by, "and without" self.grid() neither of these work, at least not as expected. any suggestions?
Jump to Post
You can pack them all into a Frame and destroy the Frame.
try: import Tkinter as tk ## Python 2.x except ImportError: import tkinter as tk ## Python 3.x class DestroyTest(): def __init__(self, top): self.top=top self.top.geometry("+10+10") self.frame=tk.Frame(self.top) self.frame.grid() test_label=tk.Label(self.frame, text="Label") test_label.grid(row=1, column=0) destroy_button=tk.Button(self.frame, text="Destroy Frame", \ command=self.destroy) …
All 3 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.