Question

I want to design an extremely simple bitmap toggle button of size 100x100 :

  • one bitmap when unpressed
  • another bitmap when pressed
  • no border
  • transparent background (ie if bitmap is a PNG, it could be transparent in some places)

I tried by subclassing wx.PyControl, but the latter has, by default, some complex things in it : borders, things to show if widget has focus or not, etc. That is too complex for my needs.

Which is the most simple wxPython container (even simpler than wx.PyControl) that I could subclass in order to create my element (I need such a container to host the images) ?

Was it helpful?

Solution

Take a look at the GenericButtons demo in the wxPython demo. Specifically look for GenBitmapToggleButton. It does most of what you want.

The transparency bit may be impossible though. In wxPython, you cannot have just one widget be translucent. It's an all or nothing affair. Check out the SetTransparent() method. You can pass it anything between 0 and 255 where 0 is completely transparent and 255 is completely solid. Here's a tutorial on it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top