Tiny buttons

Hello Michael,

  something like this may work reasonably well:

import wx
import wx.lib.buttons as buttons

class MyFrame(wx.Frame):

        def __init__(self, parent):

            wx.Frame.__init__(self, parent, size=wx.Size(300,300))
            panel = wx.Panel(self)

            label = "Ask"
            button = buttons.GenButton(panel, -1, label, pos=(30,30))
            button.SetUseFocusIndicator(False)
            button.SetBezelWidth(2)

            font = button.GetFont()
            font.SetWeight(wx.BOLD)
            button.SetFont(font)

            dc = wx.ClientDC(self)
            dc.SetFont(font)
            w, h = dc.GetTextExtent(label)
            button.SetSize((w+5, h+5))

app = wx.PySimpleApp()
frame = MyFrame(None)
frame.Show()
app.MainLoop()

You can adjust the (w+5, h+5) to fit better your needs, I just put them there because the button has a bezel width of 2 pixels.

HTH.

Andrea.

···

_________________________________________
Andrea Gavana (gavana@kpo.kz)
Reservoir Engineer
KPDL
4, Millbank
SW1P 3JA London

Direct Tel: +44 (0) 20 717 08936
Fax: +44 (0) 20 717 08900
Web: http://xoomer.virgilio.it/infinity77
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

-----Original Message-----
From: Michael Hipp [mailto:Michael@Hipp.com]
Sent: 13 April 2006 14:19
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] Tiny buttons

Similarly to the attached screen snippet, is there a way in
wxPython to draw really small crowded buttons like that "Ask" button?

It's from QuickBooks, BTW.

Michael

Gavana, Andrea wrote:

Hello Michael,

  something like this may work reasonably well:

import wx
import wx.lib.buttons as buttons

class MyFrame(wx.Frame):

        def __init__(self, parent):

            wx.Frame.__init__(self, parent, size=wx.Size(300,300))
            panel = wx.Panel(self)

            label = "Ask"
            button = buttons.GenButton(panel, -1, label, pos=(30,30))
            button.SetUseFocusIndicator(False)
            button.SetBezelWidth(2)

            font = button.GetFont()
            font.SetWeight(wx.BOLD)
            button.SetFont(font)

            dc = wx.ClientDC(self)
            dc.SetFont(font)
            w, h = dc.GetTextExtent(label)
            button.SetSize((w+5, h+5))

app = wx.PySimpleApp()
frame = MyFrame(None)
frame.Show()
app.MainLoop()

Or derived a new class and change what it uses for a best size, something like this:

class MiniButton(buttons.GenButton):
     def DoGetBestSize(self):
         w, h, useMin = self._GetLabelSize()
         return (w+4+self.bezelWidth, h+4+self.bezelWidth)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!