I started to get involved in a project written in python and wxPython (for the GUI). My task is to debug and add a few features to the GUI.

The widgets are organised mainly with sizers, and the application as a whole only looks good at a certain screen size and resolution. First thing I did was to group some elements under some panels and separate them with splitter (wx.SplitterWindow). But the hierarchy of the widgets changed; in one line of code I had to change from:

class CustomGrid(wx.grid.Grid):
    def __init__(self, parent, name, config):
        # ...
        self.data = self.GetParent().data


class CustomGrid(wx.grid.Grid):
    def __init__(self, parent, name, config):
        # ...
        self.data = self.GetParent().GetParent().GetParent().data

That's ugly. In another instance a widget class get inserted in two different places and the data is not located at the same parent level.


I am suspecting that there is something wrong with the architecture here. How to/Should I separate the data from the GUI?

Any tips and/or links to blogs or other questions would be nice to get started with. Also how to state my question better? (I'm looking forward to learning the proper lingo and perhaps edit the title!)

1 Answer 1


Relative (parent-children) widget resolution is... ugly. It makes your code set in stone and GUI unchangeable. All your widgets must be isolated from each other as much as possible.

I suggest keeping track of all relevant objects in a dictionary.

_widget_dict = {"oranges_grid": oranges.grid, "apples_window": apples.mywindow}

This is akin to **GtkBuilder in GTK+ - by keeping a reference in a book you are able to easily access them by supplying a name.

def get_widget(widget_id):
    return _widget_dict[widget_id]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.