0

I am developing an GUI-based application in Python using wxWidgets. I have a class deriving from wx.Frame, as well as a few classes deriving from wx.Panel, having all the wxpython widgets I am using.

I wonder: is there a Pythonic rule saying which wigdets should or should not be inside of self of those classes?

I can see two obvious ways to approach that:

  1. To put everything in self of a CustomPanel class. That means every widget, sizer etc. is declared as self.widget = wx.Whatever(...). That means I have access to all those objects from within methods of the class (and methods of other classes can access those objects as well) and the code is rather tidy. The disadvantage is that I am cluttering self with objects I do not need to access: although is it a problem anyway?
  2. To put in self only those widgets I do have to access in methods. That has basically the opposite features of the abovementioned solutions: on the one hand it makes self less cluttered, on the other it makes the code arguably less consistent, as some widgets are in self and some are not. It also makes debugging just a tad more difficult, as I do not have an easy access to those widgets that are not in self from within the debugger.

I would very much welcome your opinions on this subject, as I have no idea what approach would be considered better.

Kind regards!

0 Answers0