def SetFontToFitLabel(self, font = None):
        ''' Sets the internal font size so that the label will fit on the button.'''
        ''' font parameter is used to get the font specificiation only - the size does not matter. '''
        ''' If no font parameter is given, the current font is used. '''
        label = self.GetLabel().strip()
        if not label:
            return
            
        if not font:
            font = self.GetFont()
        
        # Get a known font size based on the font specification.
        fontPixels = 48
        fontCur = wx.FontFromPixelSize((0,fontPixels), font.GetFamily(), font.GetStyle(), font.GetWeight(),
                                        font.GetUnderlined(), font.GetFaceName(), font.GetEncoding() )
        dc = wx.WindowDC( self )
        dc.SetFont( fontCur )        
        
        lines = label.strip().split('\n')
        tw, th = dc.GetTextExtent( lines[0] )
        
        x, y, width, height = self.GetClientRect()
        
        # Get the centre of the button and the drawable radius.
        r = min(width, height) // 2
        xCenter = x + width // 2
        yCenter = y + height // 2
        rDrawable = r * 0.80 * 0.93 * 0.95
        
        # For all lines, check the top and bottom corners and get the maximum radius.
        r2Max = 0
        yCur = yCenter - th * len(lines) / 2.0
        for line  in lines:
            twCur, thCur = dc.GetTextExtent( line )
            tx, ty = xCenter - twCur / 2, yCur
            dx, dy = tx - xCenter, ty - yCenter
            r2Max = max( r2Max, dx*dx + dy*dy )
            dy += th
            r2Max = max( r2Max, dx*dx + dy*dy )
            yCur += th
            
        # Adjust the font size based on the ratio that we would have drawn outside the button circle.
        fontPixels *= rDrawable / math.sqrt( r2Max )
        fontCur = wx.FontFromPixelSize((0,fontPixels), font.GetFamily(), font.GetStyle(), font.GetWeight(),
                                font.GetUnderlined(), font.GetFaceName(), font.GetEncoding() )
        self.SetFont( fontCur )
 Sets the internal font size so that the label will fit on the button.
recipes/Python/577951_wxPythDramatic_shaded_3D_buttons_that_look_like_/recipe-577951.py