ttk::checkbutton as toggle switch display

checkButtonToggle

Current Version: 2.6.2 (2021-6-21)

SourceForge: https://sourceforge.net/projects/tcl-checkbuttontoggle/

bll 2021-6-21: Version 2.6.2 supports Tcl/Tk version 8.7.

bll 2020-10-25: Version 2.3 is updated to work with awthemes 9.4.2. Version 2.4 adds support for the awthemes scale.factor setting. Version 2.5 adds support for the yaru theme. (image below has been updated, it will take some time for the cache to clear. See the image on sourceforge).

bll 2019-12-3: Version 2.0 has reworked handling of .svg files and better colors. Mac OS will use the accent color.

bll 2019-10-4. Version 1.11 has reworked graphics so that the tksvg package may be used. If you have the tksvg package available, the togglei/[0-9]* folders may be removed.

bll 2016-4-26. This code provides an alternative styling of ttk::checkbutton as a toggle switch. This style of switch is becoming more common in user interfaces. There are currently 13 different switch styles in order to support the 30 different ttk themes. The package will select a toggle switch style upon load, and a bind to <<ThemeChanged>> sets it when the theme is changed.

The user can set any of the themes as a default and can use multiple themes.

The package should be "required" after tk scaling is set

 Change Log

2.6.2 2021-06-11

  • Handle ::notksvg properly.
  • Compare Tk version, not Tcl version.
  • Fix package vcompare.

2.6.1 2021-06-10

  • Check for version Tcl version 8.7
  • Update check for svg image support.

2.5.1 2020-06-10

  • Added support for Tcl 8.7.

2.6 2020-12-13

  • Add support for adapta theme.

2.5 2020-10-23

  • Added support for yaru.

2.4 2020-10-20

  • Use awthemes scale.factor setting if available.
  • Remove internal demo; external demo code is shipped.

k 2.3 2020-10-18

  • Update code to work with awthemes-9.4.2.
  • Remove unneeded dependency on img:: packages.
  • Fixed images/caching when tksvg is available.

2.2 2020-4-20

  • Change color name for version 8.1 of awthemes.

2.1 2019-12-3

  • Allow to run without resolutions.txt.

2.0 2019-12-3

  • aqua: use accent colors.
  • Removed use of 'totitle'.
  • Rework use of .svg files.
  • Improve colors when using .svg.
  • Added missing itft1, smog, sriv themes.

Version 1.11 2019-10-4

  • Added support for tksvg
  • Reworked the graphics to work with tksvg.

Version 1.8 2018-7-29

  • Added support for the equilux theme.

Version 1.7 2018-7-22

  • Added support for the scid* themes.

Version 1.6 2018-4-23

  • Added support to check for and use the graphite color theme on Mac OS X.
  • 2018-5-10: Now available on SourceForge.

Version 1.5 2016-10-29

  • Images have been rebuilt and are much better quality.
  • Many different image sizes for different display resolutions. The widget size should match up to your tk scaling setting better.

Version 1.4 2016-5-22

  • Updated the images.
  • Updated the scaling (now uses 100%/150%/200% rather than 100/150/250)

Version 1.3 2016-5-17

  • Remove unnecessary stuff.
  • Updated the images.
  • Updated the scaling.

bll 2016-5-2. I have updated the package to include multiple sizes of images and depending on the tk scaling value, it changes which set of images gets displayed. No idea if I got the scaling quite right, but a quick test looks ok.

checkButtonToggle-demo

 Discussion

Discussion

aspect 2016-04-28: beautiful widget and a very nice example of how to do custom layout with ttk. One question - is there any particular reason you excluded Checkbutton.focus from the layout? I much prefer having it to aid keyboard navigation & accessibility. Adding it back as a parent of the new indicator element seems to work, but I've only tested very roughly with the provided demo.

bll 2016-4-27: I copied a layout from another theme. Sorry, did not check the original. I have updated the code below to match the default ttk::checkbutton.


JOB Thank you bll for providing the source. Just like to let you know, that there is something going wrong with the images provided in the package.

Error in startup script:
compressed data after stream finalize in PNG data
while executing
image create photo -data $imgdata($dnm)
...

Running on windows with a plain ActiveState installation.

bll 2015-5-3: Let me research this. It works for me in some instances and not others. This is quite odd. It works as part of my application, but it does not work as a standalone script. I found this:

    http://rkeene.org/projects/tcl/tk.fossil/info/c648c8dad1%|%http://rkeene.org/projects/tcl/tk.fossil/info/c648c8dad1%|%

And ActiveState still doesn't have 8.6.5 out.

Always requiring the Img package works.

I have updated the code to require the Img package for Tcl <8.6.5.


arjen - 2016-05-03 10:44:33

I downloaded the source code and the demo works fine. Some variants look rather similar, but that may be my display.

bll 2016-5-3: I think it is how I wrote the demo code. It lists the 7 styles (variants), then displays the toggle switch that would be displayed for any themes that are loaded. Which, being standard themes, all use the same style/variant.


JOB - 2016-05-03 Downloaded again and it works flawlessly on windows. I got more adventurous and tested it on OSX too, but here the checkbutton is only a grey box. Have not investigated any further. Looks on windows very promising. Thank you very much bll.

bll 2016-5-3: Works ok on the Mac for me.

Usage

HaO 2020-10-20: Thanks, Brad, for the beautiful widget.

The distribution contains png images in many resolutions. If tksvg is present, they may be deleted ( folders togglei/[0-9]+ ).

My personal initialization sequence with awdark is:

package require awthemes
::themeutils::setThemeColors awdark scale.factor $myCurrentfactor
package require awdark 
package require checkButtonToggle

For efficiency, "checkButtonToggle" is loaded after the choice of the theme to win an initialisation round. (bll 2020-10-20 Specifically, if 'checkButtonToggle' is loaded after the ttk::style theme use ..., 'checkButtonToggle' will only initialize one theme's set of images rather than two themes).

To display a toggle button, the style "Toggle.TCheckbutton" should be used:

::ttk::checkbutton .c -style Toggle.TCheckbutton