Search code examples
pythonwxpythonwxwidgets

Is a toolbar icon supposed to show?


I have the following code and I'm on OSX. However, I'm expecting to see a toolbar icon but I'm not seeing one. Am I doing something wrong or should it work on Windows? Here's the code

import wx

class Example(wx.Frame):
    def __init__(self, parent, title): 
        super(Example, self).__init__(parent, title=title,size=(400, 350))

        self.InitUI() 
        self.Centre() 
        self.Show()

    def InitUI(self):

        self.panel = wx.Panel(self)

        toolbar = wx.ToolBar(self, size=(-1, 128))
        toolbar.SetToolBitmapSize((128,128))


        bmp2 = wx.ArtProvider.GetBitmap(wx.ART_ADD_BOOKMARK, wx.ART_OTHER, (128,128))

        toolbar.AddLabelTool(-1, label="Add", bitmap=bmp2, 
                                         shortHelp="Add", kind=wx.ITEM_NORMAL)

        toolbar.Realize()
        self.SetToolBar(toolbar)



if __name__ == '__main__':

    app = wx.App() 
    Example(None, title='') 
    app.MainLoop()

Thanks


Solution

  • The call to Realize needs to happen after the SetToolBar. This is because there are two different kinds of toolbars on OSX and which is chosen depends on if it is attached to a frame or not, and all that happens in the Realize call. Also, OSX is picky about the size of the tools, and the 128 you use will likely be reduced to a supported size.