All of the following examples use a boring little widget whose goal is to take up space in a layout so you can see how the sizers work. Listing 11.1 gives the code for that widget, which is imported by the rest of the examples in this chapter. You'll see plenty of pictures of it throughout—it's basically a simple rectangle with a label.
Listing 11.1 The block window, used as a widget in later examples import wx class BlockWindow(wx.Panel):
def _init_(self, parent, ID=-1, label="", pos=wx.DefaultPosition, size=(100, 25)):
wx.Panel._init_(self, parent, ID, pos, size, wx.RAISED_BORDER, label)
self.label = label self.SetBackgroundColour("white")
def OnPaint(self, evt):
sz = self.GetClientSize()
dc = wx.PaintDC(self)
w,h = dc.GetTextExtent(self.label)
dc.DrawText(self.label, (sz.width-w)/2, (sz.height-h)/2)
We'll be placing several of these block widgets inside a frame using different sizers throughout this chapter. We'll start with the grid sizer.
Was this article helpful?