Search code examples
pythonuser-interfacewxpythonwxwidgetstoolbar

How to make a wx Toolbar buttons larger?


I've got a wx.Toolbar and I'd like to make the buttons larger. I've searched and can't seem to find any concrete documentation on how to do this.

I'm also wondering how well this will translate across platforms; what will happen to the buttons and icons on OSX?


Solution

  • It depends on what you want to change: is it the size of the buttons or the size of the icons ?

    To change the size of the buttons, use SetToolBitmapSize (24x24 for instance):

    toolbar.SetToolBitmapSize((24, 24))
    

    This will only change the size of the buttons, though. If you want to change the size of the icons, simply use bigger ones. The easiest way is to use wx.ArtProvider:

    wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, (24, 24))
    

    So, summing it up:

    # Define the size of the icons and buttons
    iconSize = (24, 24)
    
    # Set the size of the buttons
    toolbar.SetToolBitmapSize(iconSize)
    
    # Add some button
    saveIcon = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, iconSize)
    toolBar.AddSimpleTool(1, saveIcon, "Save", "Save current file")
    

    Remark: As SetToolBitmapSize changes the size of the buttons, not the size of the icons, you can set the buttons to be larger than the icons. This should leave blank space around the icons.