Radiobuttons

Radiobuttons are a set of entries which share a variable for their “on” value.

First, there comes a sepator:

(edit-menu 'add 'separator)

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

(define color-var (gensym))

Then, we create the radiobuttons:

(edit-menu 'add 'radiobutton
	   #:label 'red
	   #:command (lambda () (print (get-tk-var color-var)))
	   #:variable (tk-var color-var)
	   #:selectcolor 'red
	   #:value 'red)

(edit-menu 'add 'radiobutton
	   #:label 'green 
	   #:command (lambda () (print (get-tk-var color-var)))
	   #:variable (tk-var color-var)
	   #:selectcolor 'green
	   #:value 'green)

(edit-menu 'add 'radiobutton
	   #:label 'blue 
	   #:command (lambda () (print (get-tk-var color-var)))
	   #:variable (tk-var color-var)
	   #:selectcolor 'blue
	   #:value 'blue)

Finally, we set the start color to red:

(set-tk-var! color-var 'red)

Depending of the value of color-var (red, green, blue, other), the edit menu looks like one of these:

radioButtonRed radioButtonGreen radioButtonBlue radioButton

See also menu, radiobutton. For access to Tcl/Tk variables, see Checkbuttons.


© Author | Home | Sitemap