starfry
starfry

Reputation: 9943

wxpython button with stock icon but no text

I am using wxPython and would like to create a button with a stock icon and no text. If I do

wx.Button(self,wx.ID_ADD)

I get a button with a plus sign icon and the word 'Add' beside it.

How can I get a button with only the icon ?

Upvotes: 1

Views: 1643

Answers (1)

VZ.
VZ.

Reputation: 22688

At first glance, it looks like wx.BU_NOTEXT could work for this, but it actually doesn't because wxWidgets supposes that if this style is used, then the button is supposed to have a bitmap explicitly associated with it.

So the simplest fix is to actually do set this bitmap by calling btn->SetBitmapLabel(wxArtProvider::GetBitmap(wxART_PLUS, wxART_MENU)) (this is C++, but should be easily translatable to Python too). If you do it like this, you don't need to use wxID_ADD as the button ID any more, but if you still want to keep using this ID, then you also need to use wxBU_NOTEXT to get rid of the stock text.

And, unlike stock buttons, which intentionally conform to the standard platform look and so may show the icon or not depending on the platform, this code will work the same everywhere.

Upvotes: 1

Related Questions