Search code examples
wxpython

Easiest way ever to create bitmap in wxPython


Sometimes it is required to create a dummy bitmap for test purposes. To make the bitmap discernable (e. g. a red one and green one), I am searching for a way to create a wx.Bitmap with as few lines of code as possible.

What I did come up with sofar:

size_h_w = 64
bmp1 = wx.EmptyBitmapRGBA(size_h_w, size_h_w, red=255, alpha=1)
bmp2 = wx.EmptyBitmapRGBA(size_h_w, size_h_w, green=255, alpha=0)

However, the only thing I get with this is a black and transparent bitmap. How to make the color argument work?

Target is from wxPython 2.9 onward (wxMSW).


Solution

  • Try using alpha=255 (or wx.ALPHA_OPAQUE). That is the alpha level for fully opaque. Zero is fully transparent, and one is almost fully transparent.