Designing an owner-drawn control
If you find a need in your UI that can't be filled in just the right way by the controls provided in the wxPython library, you may find that you need to make your own. In the previous chapters of this book, we covered many of the building blocks that we can now look at for ways to leverage and combine to build our own controls. In this recipe, we will build our own container control that has a custom-drawn border and appearance.
Getting ready
Ensure that you have taken a look at Chapter 8, User Interface Primitives, before continuing with this recipe. This recipe will combine the use of DeviceContext
and Sizer
to create a custom control.
How to do it…
First, we will start by defining a subclass of
PyPanel
to derive our new control from, as follows:class CaptionBox(wx.PyPanel): def __init__(self, parent, caption, flag=wx.VERTICAL): super(CaptionBox, self).__init__(parent, style=wx.NO_BORDER) self.Label...