/ lib / tcltk / tk8.6 / optMenu.tcl
optMenu.tcl
 1  # optMenu.tcl --
 2  #
 3  # This file defines the procedure tk_optionMenu, which creates
 4  # an option button and its associated menu.
 5  #
 6  # Copyright (c) 1994 The Regents of the University of California.
 7  # Copyright (c) 1994 Sun Microsystems, Inc.
 8  #
 9  # See the file "license.terms" for information on usage and redistribution
10  # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11  #
12  
13  # ::tk_optionMenu --
14  # This procedure creates an option button named $w and an associated
15  # menu.  Together they provide the functionality of Motif option menus:
16  # they can be used to select one of many values, and the current value
17  # appears in the global variable varName, as well as in the text of
18  # the option menubutton.  The name of the menu is returned as the
19  # procedure's result, so that the caller can use it to change configuration
20  # options on the menu or otherwise manipulate it.
21  #
22  # Arguments:
23  # w -			The name to use for the menubutton.
24  # varName -		Global variable to hold the currently selected value.
25  # firstValue -		First of legal values for option (must be >= 1).
26  # args -		Any number of additional values.
27  
28  proc ::tk_optionMenu {w varName firstValue args} {
29      upvar #0 $varName var
30  
31      if {![info exists var]} {
32  	set var $firstValue
33      }
34      menubutton $w -textvariable $varName -indicatoron 1 -menu $w.menu \
35  	    -relief raised -highlightthickness 1 -anchor c \
36  	    -direction flush
37      menu $w.menu -tearoff 0
38      $w.menu add radiobutton -label $firstValue -variable $varName
39      foreach i $args {
40      	$w.menu add radiobutton -label $i -variable $varName
41      }
42      return $w.menu
43  }