wx.CheckBox can't change bg color properly on WIndows (Linux works)

Hi, Everyone,

I’ve got a problem on changing background color of wx.Checkbox widget. Note that this problem does not appear on Linux, but Windows doesn’t work.

The usage should be quite simple. I want eacy checkbox to change color when clicked (switched between true/false).

Firstly I created checkboxes with EVT_CHECKBOX event bound to a lambda so that when clicked, a hook will trigger, passing the checkbox object in:

Then in the hook, I do:

Which should call wx.Checkbox.SetBackgroundColor() so that the color of the checkbox will reflect its value (true/false).

This works perfect on Linux, however Windows didn’t work. I can see that the color flashed quickly but gone.

Anyone has suggestions on how to fix this on Windows? Please refer to the whole program as well if needed [1].

[1] https://github.com/xzpeter/pylibs/blob/bf45345dfa71ee69cb86e5e2d868f49f54c44e83/double-ball.py

Thanks!

Peter

One of the downsides of using native widgets is that sometimes they ignore some of the common/generic methods inherited from wx.Window, like SetBackgroundColour. We can’t do anything about it when the platform decides that certain widgets should look a certain way and refuses to do what we ask them to do.

There is a generic checkbox class that was recently added for 4.1.1, which should have no problem setting the background color. You can get it from a snapshot build, or at https://github.com/wxWidgets/Phoenix/blob/6dd5689daa3f473f7d06c2f2c956dd3bcae4538d/wx/lib/checkbox.py

Hello, Robin,

The new wx.lib.chekbox.GenCheckBox worked for me!

Thanks for answering!

Best Regards,
Peter