1 #!/usr/local/bin/wish -f
 
   3 # This script demonstrates the various widgets provided by Tk,
 
   4 # along with many of the features of the Tk toolkit.
 
   6 set auto_path "$tk_library/demos $auto_path"
 
   7 wm title . "Widget Demonstration"
 
   9 #-------------------------------------------------------
 
  10 # The code below create the main window, consisting of a
 
  11 # menu bar and a message explaining the basic operation
 
  13 #-------------------------------------------------------
 
  15 frame .menu -relief raised -borderwidth 1
 
  16 message .msg -font -Adobe-times-medium-r-normal--*-180* -relief raised -width 500 \
 
  17 -borderwidth 1 -text "This application demonstrates the widgets provided by the Tk toolkit.  The menus above are organized by widget type:  each menu contains one or more demonstrations of a particular type of widget.  To invoke a demonstration, press mouse button 1 over one of the menu buttons above, drag the mouse to the desired entry in the menu, then release the mouse button.
 
  19 To exit this demonstration, invoke the \"Quit\" entry in the \"Misc\" menu."
 
  21 pack append . .menu {top fillx} .msg {bottom expand fill}
 
  23 #-------------------------------------------------------
 
  24 # The code below creates all the menus, which invoke procedures
 
  25 # to create particular demonstrations of various widgets.
 
  26 #-------------------------------------------------------
 
  28 menubutton .menu.button -text "Labels/Buttons" -menu .menu.button.m \
 
  31 .menu.button.m add command -label "Labels" -command "mkLabel" -underline 0
 
  32 .menu.button.m add command -label "Buttons" -command "mkButton" -underline 0
 
  33 .menu.button.m add command -label "Checkbuttons" -command "mkCheck" \
 
  35 .menu.button.m add command -label "Radiobuttons" -command "mkRadio" \
 
  37 .menu.button.m add command -label "15-puzzle" -command "mkPuzzle" -underline 0
 
  38 .menu.button.m add command -label "Iconic buttons" -command "mkIcon" \
 
  41 menubutton .menu.listbox -text "Listboxes" -menu .menu.listbox.m -underline 0
 
  43 .menu.listbox.m add command -label "States" -command "mkListbox" -underline 0
 
  44 .menu.listbox.m add command -label "Colors" -command "mkListbox2" -underline 0
 
  45 .menu.listbox.m add command -label "Well-known sayings" -command mkListbox3 \
 
  48 menubutton .menu.entry -text "Entries" -menu .menu.entry.m -underline 0
 
  50 .menu.entry.m add command -label "Without scrollbars" -command "mkEntry" \
 
  52 .menu.entry.m add command -label "With scrollbars" -command "mkEntry2" \
 
  55 menubutton .menu.text -text "Text" -menu .menu.text.m -underline 0
 
  57 .menu.text.m add command -label "Basic text" -command "mkBasic" \
 
  59 .menu.text.m add command -label "Display styles" -command "mkStyles" \
 
  61 .menu.text.m add command -label "Command bindings" -command "mkTextBind" \
 
  64 menubutton .menu.scroll -text "Scrollbars" -menu .menu.scroll.m -underline 0
 
  66 .menu.scroll.m add command -label "Vertical" -command "mkListbox2" -underline 0
 
  67 .menu.scroll.m add command -label "Horizontal" -command "mkEntry2" -underline 0
 
  69 menubutton .menu.scale -text "Scales" -menu .menu.scale.m -underline 2
 
  71 .menu.scale.m add command -label "Vertical" -command "mkVScale" -underline 0
 
  72 .menu.scale.m add command -label "Horizontal" -command "mkHScale" -underline 0
 
  74 menubutton .menu.canvas -text "Canvases" -menu .menu.canvas.m -underline 0
 
  76 .menu.canvas.m add command -label "Item types" -command mkItems -underline 0
 
  77 .menu.canvas.m add command -label "2-D plot" -command mkPlot -underline 0
 
  78 .menu.canvas.m add command -label "Text" -command mkCanvText -underline 0
 
  79 .menu.canvas.m add command -label "Arrow shapes" -command mkArrow -underline 0
 
  80 .menu.canvas.m add command -label "Ruler" -command mkRuler -underline 0
 
  81 .menu.canvas.m add command -label "Scrollable canvas" -command mkScroll \
 
  84 menubutton .menu.menu -text "Menus" -menu .menu.menu.m -underline 0
 
  86 .menu.menu.m add command -label "Print hello" -command {puts stdout "Hello"} \
 
  87     -accelerator Control+a -underline 6
 
  88 bind .msg <Control-a> {puts stdout "Hello"}
 
  89 .menu.menu.m add command -label "Print goodbye" -command {\
 
  90     puts stdout "Goodbye"} -accelerator Control+b -underline 6
 
  91 bind .msg <Control-b> {puts stdout "Goodbye"}
 
  92 .menu.menu.m add command -label "Light blue background" \
 
  93     -command {.msg config -bg "LightBlue1"} -underline 0
 
  94 .menu.menu.m add command -label "Info on tear-off menus" -command mkTear \
 
  96 .menu.menu.m add cascade -label "Check buttons =>" -menu .menu.menu.m.check \
 
  98 .menu.menu.m add cascade -label "Radio buttons =>" -menu .menu.menu.m.radio \
 
 100 .menu.menu.m add command -bitmap @$tk_library/demos/bitmaps/pattern \
 
 102         mkDialog .pattern {-text {The menu entry you invoked displays a bitmap rather than a text string.  Other than this, it is just like any other menu entry.} -aspect 250} {OK {}}
 
 105 menu .menu.menu.m.check
 
 106 .menu.menu.m.check add check -label "Oil checked" -variable oil
 
 107 .menu.menu.m.check add check -label "Transmission checked" -variable trans
 
 108 .menu.menu.m.check add check -label "Brakes checked" -variable brakes
 
 109 .menu.menu.m.check add check -label "Lights checked" -variable lights
 
 110 .menu.menu.m.check add separator
 
 111 .menu.menu.m.check add command -label "Show current values" \
 
 112     -command "showVars .menu.menu.dialog oil trans brakes lights"
 
 113 .menu.menu.m.check invoke 1
 
 114 .menu.menu.m.check invoke 3
 
 116 menu .menu.menu.m.radio
 
 117 .menu.menu.m.radio add radio -label "10 point" -variable pointSize -value 10
 
 118 .menu.menu.m.radio add radio -label "14 point" -variable pointSize -value 14
 
 119 .menu.menu.m.radio add radio -label "18 point" -variable pointSize -value 18
 
 120 .menu.menu.m.radio add radio -label "24 point" -variable pointSize -value 24
 
 121 .menu.menu.m.radio add radio -label "32 point" -variable pointSize -value 32
 
 122 .menu.menu.m.radio add sep
 
 123 .menu.menu.m.radio add radio -label "Roman" -variable style -value roman
 
 124 .menu.menu.m.radio add radio -label "Bold" -variable style -value bold
 
 125 .menu.menu.m.radio add radio -label "Italic" -variable style -value italic
 
 126 .menu.menu.m.radio add sep
 
 127 .menu.menu.m.radio add command -label "Show current values" -command \
 
 128     "showVars .menu.menu.dialog pointSize style"
 
 129 .menu.menu.m.radio invoke 1
 
 130 .menu.menu.m.radio invoke 7
 
 132 menubutton .menu.misc -text Misc -menu .menu.misc.m -underline 1
 
 134 .menu.misc.m add command -label "Modal dialog (local grab)" -command {
 
 135     mkDialog .modal {-text {This dialog box is a modal one.  It uses Tk's "grab" command to create a "local grab" on the dialog box.  The grab prevents any pointer-related events from getting to any other windows in the application.  If you press the "OK" button below (or hit the Return key) then the dialog box will go away and things will return to normal.} -aspect 250 -justify left} {OK {}}
 
 137     bind .modal <Visibility> {grab .modal; focus .modal}
 
 139 .menu.misc.m add command -label "Modal dialog (global grab)" -command {
 
 140     mkDialog .modal {-text {This is another modal dialog box.  However, in this case a "global grab" is used, which locks up the display so you can't talk to any windows in any applications anywhere, except for the dialog.  If you press the "OK" button below (or hit the Return key) then the dialog box will go away and things will return to normal.} -aspect 250 -justify left} {OK {}}
 
 142     bind .modal <Visibility> {grab -global .modal; focus .modal}
 
 144 .menu.misc.m add command -label "Quit" -command "destroy ." -underline 0
 
 146 pack append .menu .menu.button left .menu.listbox left \
 
 147     .menu.entry left .menu.text left .menu.scroll left .menu.scale left \
 
 148     .menu.canvas left .menu.menu left .menu.misc left
 
 150 # Set up for keyboard-based menu traversal
 
 152 tk_bindForTraversal .msg
 
 153 bind . <Any-Enter> {focus .msg}
 
 154 tk_menus . .menu.button .menu.listbox .menu.entry .menu.text \
 
 155         .menu.scroll .menu.scale .menu.canvas .menu.menu .menu.misc
 
 157 # Position a dialog box at a reasonable place on the screen.
 
 160     wm geometry $w +300+300