roninpawn / guiABLE

MIT License
2 stars 1 forks source link

Image references get lost in Toggleable() class #1

Closed roninpawn closed 5 years ago

roninpawn commented 5 years ago

Hey dork! You totally borked the image-management thing you said you were "just going to handle" so people wouldn't end up losing their image references. What a stoop u R!

cough

Observed when spawning an instance of a class within an instance of a class, both of which are tk.Tk() windows. Spawning Toggleables() in the "child" window fails with

_tkinter.TclError: image "pyimage1" doesn't exist

Since the Toggleable class adds 4 more images to the usual list of 4, I'm thinking the source reference to the original is getting picked up in garbage collection or something. Which is what I thought I'd designed around. And it sure looked like it until I spawned a Toggleable in a window spawned from a window in a class embedded in the first window's class.

... What?

roninpawn commented 5 years ago

I'm not 1000% sure this was actually a bug. It may have just been an implementation issue. The nesting of one Tk() window, when spawned from within another Tk() window, seemed to break all linkages. And that kind of makes sense. I'm thinking of it like this:

The nested Tk() window is instantiated within the first, but it has no linkage going back to the one it was instantiated from. It's a free-operator, created in its own root-space. Which means trying to call back to any variable in the first Tk() window's namespace would require accessing it like a neighbor, not a tenant.

You can't shout into the kitchen, "WHERE'S THE PEANUT BUTTER?" because you aren't in a room inside the house. You're in the house next door. You have to walk across the yard, knock, and ask politely if you can borrow some peanut butter.

Interestingly, though, the nested Tk() window couldn't see variables created in the base code either, outside of any class or function. Which means the nested Tk() lacked reference back to the object that spawned it - which is all well and good - but also lacked reference to the main code.

So, maybe my analogy is wrong... You can't shout "WHERE'S THE PEANUT BUTTER?," but you also can't walk next door and borrow some, because you aren't in the house, or the house next door... You're in a parallel dimension of empty white void. And if you didn't bring it with you, you won't find it here.

I guess what I'm saying is: I dunno how to explain this, but I think I fixed it in the current pre-release, (https://github.com/roninpawn/guiABLE/tree/pre-release) and also recommend not instantiating Tk()'s from within Tk()'s. Toplevels register their parent-window and allow for window nesting. Unless you've got a Tardis handy, don't smack the flux capacitor.