Icon in wx.Toolbar

Hi,

I am a new learner. I made this script following zetcode nice tutorial:

class CheckMenuItem(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(350, 250))

        menubar = wx.MenuBar()
        file = wx.Menu()
        view = wx.Menu()
        self.shst = view.Append(ID_STAT, 'Show statusbar', 'Show Statusbar', kind=wx.ITEM_CHECK)
        self.shtl = view.Append(ID_TOOL, 'Show toolbar', 'Show Toolbar', kind=wx.ITEM_CHECK)
        view.Check(ID_STAT, True)
        view.Check(ID_TOOL, True)

        self.Bind(wx.EVT_MENU, self.ToggleStatusBar, id=ID_STAT)
        self.Bind(wx.EVT_MENU, self.ToggleToolBar, id=ID_TOOL)

        menubar.Append(file, '&File')
        menubar.Append(view, '&View')
        self.SetMenuBar(menubar)

        self.toolbar = self.CreateToolBar()
        tsize = (24,24)
        quit_bmp = wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR, tsize)
        self.toolbar.SetToolBitmapSize(tsize)
        self.toolbar.AddLabelTool(3, '', quit_bmp)

        self.statusbar = self.CreateStatusBar()
        self.Centre()
        self.Show(True)

    def ToggleStatusBar(self, event):
        if self.shst.IsChecked():
            self.statusbar.Show()
        else:
            self.statusbar.Hide()

    def ToggleToolBar(self, event):
        if self.shtl.IsChecked():
            self.toolbar.Show()
        else:
            self.toolbar.Hide()

app =wx.App()
CheckMenuItem(None, -1, 'check menu item')
app.MainLoop()

then when I run it, the icon on toolbar did now appear. Is that any limitation in using icon in toolbar? How to fix the script?

regards,

Mico

Hello,

You need to call Toolbar.Realize() after you setup your toolbar (i.e self.toolbar.Realize()).

···

On Aug 5, 2008, at 5:18 PM, Mico Siahaan wrote:

class CheckMenuItem(wx.Frame):
   def __init__(self, parent, id, title):
       wx.Frame.__init__(self, parent, id, title, size=(350, 250))

       menubar = wx.MenuBar()
       file = wx.Menu()
       view = wx.Menu()
       self.shst = view.Append(ID_STAT, 'Show statusbar', 'Show Statusbar', kind=wx.ITEM_CHECK)
       self.shtl = view.Append(ID_TOOL, 'Show toolbar', 'Show Toolbar', kind=wx.ITEM_CHECK)
       view.Check(ID_STAT, True)
       view.Check(ID_TOOL, True)

       self.Bind(wx.EVT_MENU, self.ToggleStatusBar, id=ID_STAT)
       self.Bind(wx.EVT_MENU, self.ToggleToolBar, id=ID_TOOL)

       menubar.Append(file, '&File')
       menubar.Append(view, '&View')
       self.SetMenuBar(menubar)

       self.toolbar = self.CreateToolBar()
       tsize = (24,24)
       quit_bmp = wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR, tsize)
       self.toolbar.SetToolBitmapSize(tsize)
       self.toolbar.AddLabelTool(3, '', quit_bmp)

       self.statusbar = self.CreateStatusBar()
       self.Centre()
       self.Show(True)

   def ToggleStatusBar(self, event):
       if self.shst.IsChecked():
           self.statusbar.Show()
       else:
           self.statusbar.Hide()

   def ToggleToolBar(self, event):
       if self.shtl.IsChecked():
           self.toolbar.Show()
       else:
           self.toolbar.Hide()

app =wx.App()
CheckMenuItem(None, -1, 'check menu item')
app.MainLoop()