Checkbuttons

A checkbutton is a menu entry which has an “on” and an “off” state. The state is stored in a Tcl/Tk variable. We gain access to this variable by the functions (tk-var name), (get-tk-var name), (set-tk-var! name value).

First, there comes a sepator:

(edit-menu 'add 'separator)

We create an unique name and bind it to the symbol brightness-var:

(define brightness-var (gensym))

Then, we add the checkbutton:

(edit-menu 'add 'checkbutton
           #:label 'bright
           #:command (lambda () (print (get-tk-var brightness-var)))
           #:variable (tk-var brightness-var))

If you enter in the console:

(set-tk-var! brightness-var 0)

then the torn-off edit menu looks like this:

menuCheckButton

If you enter in the console:

(set-tk-var! brightness-var 1)

then the torn-off edit menu looks like this:

menuCheckButton1

You can always read the Tcl/Tk variable:

(get-tk-var brightness-var)

© Author | Home | Sitemap