An On/Off button alternative to CheckBox

This is in reply to ZigZag about an issue with onoffbutton.py, which I, unfortunately, can’t recall where I originally posted.
I’m prepared to admit, I removed all traces of Microsoft from my life some 20 years ago, so I only test code on Linux. I also test on the version of python, currently 3.8.10, which comes standard on my OS.
I avoid virtual machines, as the box I have is tiny, due to living off grid and electricity shortfalls.
My excuses made, as far as I can tell, the issues lie with python3 version 10+ being more fussy about things and MS Windows.
Feel free to test this updated version and get back to me if there are still issues. I expect there could still be an issue around font.GetPixelSize(), where if it isn’t available I simply guess. I have no way of testing it, as it works happily on Linux.

Update: 2nd attempt to resolve font issues

onoffbutton.py (22.4 KB)

:wink:

Morning da-dada,
I very much appreciate the input, put it down to me being a bit of pratt and not thinking beyond my own box.
Hopefully, that issue is now resolved in the updated code.
An invalid font is now swapped out for the system gui font and the label size calculation, is performed using a DC.

Regards Rolf

As these things are never finished, here is version 1.15.4 with various control styles.
onoffbutton.py (31.3 KB)

I’d like to thank Zig Zag for testing on the Windows platform
and at Zig Zag’s request, post a copy of ToggleButtonBitmap.

A custom class On/Off clickable image, where you supply an Off image and an On image
The images are scaled according to the size parameter you supply

ToggleButtonBitmap.2.0.0.zip (375.3 KB)