Let's say a user of my application opens two or more MDIChildFrames. How can I get access to any one of the child frames? If I keep track of the names of the child frames in a list is there a way to use the name to call upon a certain MDIChildFrame?

Dani AI

Generated

Good catch, . A simple registry solves the immediate problem, but in production code it's worth hardening that idea so closed windows don't stay referenced, keys stay unique, and cleanup happens reliably. Two practical patterns: keep a lightweight registry that does not pin objects (use weak references), or query the parent for its children when you only need a current snapshot.

Example (wxPython-friendly) pattern: use a WeakValueDictionary for the registry and remove the mapping when the child closes. This avoids keeping closed frames alive and makes lookups trivial.

from weakref import WeakValueDictionary
import wx

_child_registry = WeakValueDictionary()

def register_child(child, key):
_child_registry[key] = child
def _on_close(evt, k=key):
_child_registry.pop(k, None)
evt.Skip()
child.Bind(wx.EVT_CLOSE, _on_close)
child.Show()

def get_child(key):
return _child_registry.get(key)

Extra tips: prefer a stable logical id (not the visible window title) as the key to avoid collisions; many toolkits let you enumerate children from the parent (e.g., parent.GetChildren()) or get the active MDI child directly — use those when you need a snapshot rather than a persistent index. Always perform GUI operations on the GUI thread and bind close/destroy events to ensure prompt cleanup. See Python's weakref documentation for WeakValueDictionary (weakref.WeakValueDictionary) and the wx MDI child lifecycle for toolkit specifics (wx.MDIChildFrame docs).

I figured it out. I just stored the names of the child frames as the keys to their respective childframes in a dictionary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.