I sometimes like to use small, compact toggle buttons to show whether certain settings in an application are enabled or disabled and to allow those settings to be toggled by the user.
The toggle buttons will display simple bitmaps or short text strings to indicate their purpose, which can be amplified by tooltips.
However, I don’t find the default appearance of wx.ToggleButton
s makes it obvious to me whether the buttons are ‘on’ or ‘off’, This is because they show a darker grey background when they are pressed, or ‘on’. I associate ‘greyed-out’ buttons with them being disabled and thus find the appearance of wx.ToggleButtons
to be counter-intuitive.
I find the generic toggle buttons provided by the wx.lib.buttons
module to be an improvement as their backgrounds turn a lighter grey and they have an obvious 3-D pressed-in look when they are pressed, or ‘on’.
I wondered if it would be even more obvious if they also showed an indicator somewhat like a coloured LED when they were ‘on’? As an experiment I created the IndicatorToggleButton
class (derived from GenBitmapToggleButton
) which shows a coloured bar underneath the bitmap when the button is ‘on’. This uses some utility functions to create two new bitmaps based on the original bitmap but which have 4 extra rows of pixels at the bottom. For the bitmap used for the ‘off’ position the extra 4 rows are left blank. For the bitmap for the ‘on’ position the indicator is drawn across the 2nd and 3rd rows. I also created 2 derived classes which take either the pathname of an image file or a short piece of text in order to create the original bitmap for a button.
Here is a demonstration of the 3 types of toggle buttons:
Even if you don’t prefer the IndicatorToggleButtons
you may find the techniques useful, so I have uploaded the code and the two image files in the following zip file: compare_toggle_buttons.zip (3.4 KB)
Tested using Python 3.10.12 + wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 on Linux Mint 21.2