How to use a png image as a toolbar button icon?

171 views
Skip to first unread message

steve

unread,
Dec 8, 2015, 5:43:53 AM12/8/15
to wxPython-users
I have some set of png images, I'd like to use them as button icons in my toolbar (wx.ToolBar).
 
I do:
 
ID_DRAW_BUTTON = 100
self.toolbar = wx.ToolBar(self, -1, style=wx.TB_FLAT|wx.BORDER_RAISED)
 
draw_icon = wx.ArtProvider.GetBitmap("chart-icon", wx.ART_TOOLBAR, (16,16))
self.toolbar.AddTool(ID_DRAW_BUTTON, "Draw", draw_icon, shortHelpString="Draw Chart")
 
But it says
 
TypeError: in method 'ToolBarBase_DoAddTool', expected argument 4 of type 'wxBitmap const &'
 
although type of draw_icon is <class 'wx._gdi.Bitmap'>
 
So what should I do to use a png image as a toolbar button  icon?

Werner

unread,
Dec 8, 2015, 6:36:31 AM12/8/15
to wxpytho...@googlegroups.com
What wxPython version?

Isn't arg 4 the disabled bitmap?  If you haven't one you can pass NullBitmap.

Werner

Metallicow

unread,
Dec 28, 2015, 10:26:27 PM12/28/15
to wxPython-users

try this. wx3.0.2 call
wx.ToolBar.AddTool(self, id, bitmap=mybitmap, pushedBitmap=mybitmap, isToggle=0, clientData=None, shortHelpString='', longHelpString='')
It might differ a bit on older wxversions as far as arg placement or args.

John Fabiani

unread,
Dec 29, 2015, 10:00:04 PM12/29/15
to wxpython-users
I'm not sure the following is actually helpful.  I have tried several methods (in the general use of the word not python method) of adding graphics (png,jpeg, icon, etc..) to toolbar panels.  What I discovered was that in the end I needed a button.  Once I started using buttons all worked well and as expected.  Playing with the background and pic I got very good results.  So try something like:
self.clearbtn = wx.Button(self, -1,label = 'Clear' )
self.clearbtn.SetBackgroundColour(wx.CYAN)
self.clearbtn.SetBitmap(wx.Bitmap('icons/edit-clear32.png'),wx.LEFT)
then add the button to the toolbar.
Johnf

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages