I'm having an issue with my Python code, I'm using Tkinter to make an App and switch between windows, one of the windows has the following code:
def __init__(self, master):
tk.Frame.__init__(self, master)
master.title("Chain Targets:")
master.geometry("400x800")
tk.Label(self, text="Chain Targets").grid()
self.sbox = tk.Listbox(master)
self.sbox.grid(row=0, column=0)
number=1
for k in sorted(target_list, key=target_list.get, reverse=True):
place_target= str(number) + " " + k + " " + str(target_list[k])
self.sbox.insert(number,place_target)
number+=1
tk.Scrollbar.grid(self)
tk.Button(self, text="Main Menu",
command=lambda: master.switch_frame(MainPage)).grid()
Now this all works fine, except when using the switch_frame function the Listbox stays in the new screen, the switch_frame function is the following:
def switch_frame(self, frame_class):
"""Destroys current frame and replaces it with a new one."""
new_frame = frame_class(self)
if self._frame is not None:
self._frame.destroy()
self._frame = new_frame
self._frame.grid()
somehow I can't wrap my head around the fact that the self._frame.destroy() doesn't destroys the Listbox and it stays in every window in the top, for the rest my code does everything it's intended to do. I hope someone has an idea of what I am missing.
master, i.e. the root window.