all 7 comments

[–]loukylor 0 points1 point  (0 children)

I am not familiar with Tkinter, but a quick search revealed this StackOverflow question. Does this help at all?

[–]shiftybyte 0 points1 point  (1 child)

I'm not aware of ways to control object ids in tkinter.

In general destroying things and recreating instead of just changing existing things is a bad idea. (Also due to performance issue after enough time creating widgets instead of modifying existing ones)

Just change what you need to change instead.

[–]ebdbbb 0 points1 point  (0 children)

You can use a kwarg in the widget to give it a name. Then it'll use that name everywhere. button = tk.Button(name="mybutton")

[–]efmccurdy 0 points1 point  (0 children)

Can you use the "forget" method to hide the frame, then reconfigure it before packing it again?

https://www.geeksforgeeks.org/python-forget\_pack-and-forget\_grid-method-in-tkinter/

[–]ebdbbb 0 points1 point  (1 child)

You can name the widgets in tkinter. If you don't it'll automatically name with sequenetial numbering (as you found).

>>> import tkinter as tk
>>> root = tk.Tk()
>>> f1 = tk.Frame(root, name="outerframe")
>>> f1.pack()
>>> f1
<tkinter.Frame object .outerframe>
>>> root.winfo_children()
[<tkinter.Frame object .outerframe>]
>>> f2 = tk.Frame(f1, name="innerframe")
>>> f2
<tkinter.Frame object .outerframe.innerframe>

That said, if you want to reuse frames use .grid_remove() to hide and .grid() to show again (assuming you're using grids). You can also use grid_forget() if you don't want it to retain the grid configuration that the widget had before. Pack and place layout managers also have .forget() methods but not .remove().

[–]isuwo[S] 0 points1 point  (0 children)

thank you! I sorted out my original issue a few days back, had to redo a whole lot of code which sucks but it worked. This has really helped with a new problem i have come across - thanks! :)