The joptionbutton.tcl library is distributed as part of the jstools package. It provides a button that pops up an option menu so your users can make a oneofmany choice. It's equivalent in functionality to a group of radio buttons, but a little easier to use and more sparing of screen realestate.
This document describes joptionbutton.tcl version 4.0/4.0.
In order to use the joptionbutton.tcl library, it (and any other libraries it depends on) must be in your Tcl auto_path, described in tclvars(n). Information about how to arrange that, and other conventions common to the jstools libraries, is in the Usage section of The jstools Libraries.
Jay Sekora
js@calumet.org
http://shore.net/~js/
Copyright
The library is copyright © 1992-1995 by Jay Sekora, but may be freely redistributed under the conditions at the top of the file.
j:option - create option button with associated menu
j:option:configure - set attributes of option button
j:option:popup - pop up option button's menu
j:option w [options]
w is the name of the new option button to create
-font font (default {})
-list list (default "(none)"; not really optional)
-width width (default 20)
-current current (default first element of list)
toplevel .prefs
j:option .prefs.colour -list {red yellow blue} \
-current $PREFS(colour)
pack .prefs.colour
bind .prefs.ok {set PREFS(colour) [.prefs.colour get]}
This procedure creates a new option button, w, with an associated menu, which can be posted by clicking on the button. An option button is useful for asking the user to select one option from a constrained set of choices. The menu will contain all the elements of list, and the button will be labelled with current. If current is not in list, it will be added to the beginning of list the first time the menu is brought up. Choosing another item from the menu will cause the button's text to change to that item, and cause the item to become the new current value of the option button. If font is specified and nonnull, both the button and the menu will be displayed in that font. The menu will be width characters wide, and the button will also be width characters wide unless it is packed in such a way as to change its dimensions.
The current value of the button can be manipulated with the
get and
set widget commands, and the current values of the widget options
can be changed or retrieved with the
configure widget command.
w get
This widget command returns the current value of the option button.
w set value
This widget command sets the current value of the option button.
w configure option [argument]
This widget command lets you retrieve (if argument is omitted) or set (if it is provided) the current value of any of the options, font, list, width, or current.
j:option:configure w option [argument]
w is the pathname of the option button to be configured
option is one of -font, -list, -current, or -width
argument, if specified, is the new value of option
This procedure is used internally by j:option, and should not need to be called directly. It implements the configure widget command.
j:option:popup w button
w is the pathname of the frame to hold the popup menu
button is the pathname of the option button
This procedure is used internally by j:option, and should not need to be called directly. It is invoked when an option button is clicked on. It creates a new frame w, packs a listbox in it to simulate a menu, positions it appropriately over the option button, and sets up mouse bindings letting the user select an item from the listbox. (The reason for using a listbox rather than a menu is that the width of a menu can't be set.)
If an option button is packed such that it's larger or smaller than its requested width (as specified by the -width option), its menu will be the wrong size.
Only one option at a time can be specified to j:option:configure, and hence to the configure widget command.
* I'm probably going to rewrite this to be more compatible with the Tk 4.0 tk_optionMenu procedure.