Sometimes it's nice to have a simple background pattern in a wx Panel, Window of Frame. The following example uses a rather dark colored hatch pattern. You'll probably want to use a more subtle color. Several simple automatically generated patterns are available - see the various wx.Brush() styles when using dc.DrawRectangle to draw the pattern. If you want full control of the background pattern you can substitute a series of dc.DrawLine() and other dc drawing calls to draw a pattern of your choosing. Consider how wxPython draws the hatch pattern shown below. It's not very difficult to code something similar yourself. Class variable [ self.hatchedWinBorder ] is set to 15 in the demo. Set it to 0 to make the hatched window fill the parent Frame. {{attachment:HatchedWindow_1.png}} In the next shot the frame was resized which not only resized the hatched window, but also redrew it using a dc. Notice how the hatch line spacings remain the same. The hatched window's parent container control, the Frame, is responsible for the size and placement of the hatched window while the window redraws itself on the Frame's resize events. Within the Frame class definition : {{{#!python def OnSize( self, event ) : """ Define/redefine the position and size of the hatched window A wx.EVT_SIZE event generates a wx.EVT_PAINT event in objects # created from the class (instantiated from the class definition). Every wx.EVT_SIZE event generates a wx.EVT_PAINT event. This paint handler is just a pass-through. """ self.CenterHatchedWinInHwPanel() event.Skip() #end def #---------------------------------- def CenterHatchedWinInHwPanel( self ) : # The slider value [0..100] will set the hatched window size to [0..100%] # of each client axis containing self.hwPanel hwPanelWidth, hwPanelHeight = self.hwPanel.GetClientSize() # Resize hatchedWin newHwinWidth = int( (self.sliderValue / 100.0) * hwPanelWidth + 0.5) newHwinHeight = int( (self.sliderValue / 100.0) * hwPanelHeight + 0.5) newWinSize = (newHwinWidth, newHwinHeight) self.hatchedWin.SetSize( newWinSize ) # Reposition hatchedWin newHwinPosX = (hwPanelWidth - newHwinWidth) / 2 newHwinPosY = (hwPanelHeight - newHwinHeight) / 2 newHwinPos = (newHwinPosX, newHwinPosY) self.hatchedWin.SetPosition ( newHwinPos ) self.Layout() # Resize and reposition its controls. self.hwPanel.Refresh( False ) #end def }}} The hatched panel's wx.EVT_PAINT handler : {{{#!python def OnPaint( self, event=None ) : dc = wx.PaintDC( self ) selfSizeX, selfSizeY = self.GetSize() # Define the background pattern. The HatchedWindow background color is retained. hatchColor = (0, 75, 0) # dark green - use any color dc.SetPen( wx.Pen( hatchColor, 1 ) ) bgPattern = wx.BDIAGONAL_HATCH # See the various wx.Brush() styles. dc.SetBrush( wx.Brush( hatchColor, bgPattern ) ) dc.DrawRectangle( 0, 0, selfSizeX, selfSizeY ) """ # Overdraw the original rectangle outline with another color. dc.SetPen( wx.Pen( 'wHiTe', 5 ) ) # use any color dc.SetBrush( wx.Brush( 'BluE', wx.TRANSPARENT ) ) # Leave the interior intact dc.DrawRectangle( 0, 0, selfSizeX, selfSizeY ) """ event.Skip() #end OnPaint def }}} {{attachment:HatchedWindow_2.png}} [[attachment:HatchedWindow.py]] The next demo gets fancier by managing the HatchedWindow's size by a slider position. The wx.Slider is positioned at the bottom of the Frame using a sizer. The rest of the Frame client area is taken up by a second panel that holds the hatched window. The HatchedWindow's size and position are calculated using the current slider position and the current panel dimensions. How it all works is explained in the comments. It's important to note that no sizer can easily manage the position of the hatched window because a sizer's most important function is to auto-size, but the size must be calculated from the slider position : {{{#!python def CenterHatchedWinInHwPanel( self ) : # The slider value [0..100] will set the hatched window size to [0..100%] # of both client axes of self.hwPanel that contains self.hwPanel hwPanelWidth, hwPanelHeight = self.hwPanel.GetClientSize() # Resize hatchedWin using the slider position value. newHwinWidth = int( (self.sliderValue / 100.0) * hwPanelWidth + 0.5) newHwinHeight = int( (self.sliderValue / 100.0) * hwPanelHeight + 0.5) newWinSize = (newHwinWidth, newHwinHeight) self.hatchedWin.SetSize( newWinSize ) # Reposition hatchedWin newHwinPosX = (hwPanelWidth - newHwinWidth) / 2 newHwinPosY = (hwPanelHeight - newHwinHeight) / 2 newHwinPos = (newHwinPosX, newHwinPosY) self.hatchedWin.SetPosition ( newHwinPos ) self.Layout() # The sizer will resize and reposition its controls. self.hwPanel.Refresh( False ) #end def }}} [[attachment:HatchedWin_Slider.py]] {{attachment:HatchedWinSizedUsingSLider_1.png}} {{attachment:HatchedWinSizedUsingSLider_2.png}} {{attachment:HatchedWinSizedUsingSLider_3.png}} When the Frame's size is changed the size of both the hatched window and the slider are adjusted. The self.frmPnl_vSzr is configured to keep the slider's height to stay fixed while the size of self.frmPnl_vSzr is fully flexible. The hatched window's "manual" sizing and positioning code maintains the ratio of the lengths of the hatched window ( its "aspect ratio" ) to remain constant on slider changes. {{attachment:HatchedWinSizedUsingSLider_4.png}} Despite changes in the Frame's size the aspect ratio of the hatched window is fixedfor any given slider value. --- Ray Pasco 2011, July Send your questions and comments to pascor(at)verizon(dot)net