home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tkisrc04.zip / lib / tk / demos / menu.tcl < prev    next >
Text File  |  1998-09-09  |  5KB  |  122 lines

  1. # menu.tcl --
  2. #
  3. # This demonstration script creates a window with a bunch of menus
  4. # and cascaded menus.
  5. #
  6. # SCCS: @(#) menu.tcl 1.7 96/04/12 11:57:35
  7.  
  8. set w .menu
  9. catch {destroy $w}
  10. toplevel $w
  11. wm title $w "Menu Demonstration"
  12. wm iconname $w "menu"
  13. positionWindow $w
  14.  
  15. frame $w.menu -relief raised -bd 2
  16. pack $w.menu -side top -fill x
  17.  
  18. label $w.msg -font $font -wraplength 4i -justify left -text "This window contains a collection of menus and cascaded menus.  You can post a menu from the keyboard by typing Alt+x, where \"x\" is the character underlined on the menu.  You can then traverse among the menus using the arrow keys.  When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character.  If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator."
  19. pack $w.msg -side top
  20.  
  21. frame $w.buttons
  22. pack $w.buttons -side bottom -fill x -pady 2m
  23. button $w.buttons.dismiss -text Dismiss -command "destroy $w"
  24. button $w.buttons.code -text "See Code" -command "showCode $w"
  25. pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
  26.  
  27. set m $w.menu.file.m
  28. menubutton $w.menu.file -text "File" -menu $m -underline 0
  29. menu $m
  30. $m add command -label "Open ..." -command {error "this is just a demo: no action has been defined for the \"Open ...\" entry"}
  31. $m add command -label "New" -command {error "this is just a demo: no action has been defined for the \"New\" entry"}
  32. $m add command -label "Save" -command {error "this is just a demo: no action has been defined for the \"Save\" entry"}
  33. $m add command -label "Save As ..." -command {error "this is just a demo: no action has been defined for the \"Save As ...\" entry"}
  34. $m add separator
  35. $m add command -label "Print Setup ..." -command {error "this is just a demo: no action has been defined for the \"Print Setup ...\" entry"}
  36. $m add command -label "Print ..." -command {error "this is just a demo: no action has been defined for the \"Print ...\" entry"}
  37. $m add separator
  38. $m add command -label "Quit" -command "destroy $w"
  39.  
  40. set m $w.menu.basic.m
  41. menubutton $w.menu.basic -text "Basic" -menu $m -underline 0
  42. menu $m
  43. $m add command -label "Long entry that does nothing"
  44. foreach i {a b c d e f g} {
  45.     $m add command -label "Print letter \"$i\"" -underline 14 \
  46.         -accelerator Meta+$i -command "puts $i"
  47.     bind $w <Meta-$i> "puts $i"
  48. }
  49.  
  50. set m $w.menu.cascade.m
  51. menubutton $w.menu.cascade -text "Cascades" -menu $m -underline 0
  52. menu $m
  53. $m add command -label "Print hello" \
  54.     -command {puts stdout "Hello"} -accelerator Control+a -underline 6
  55. bind . <Control-a> {puts stdout "Hello"}
  56. $m add command -label "Print goodbye" -command {\
  57.     puts stdout "Goodbye"} -accelerator Control+b -underline 6
  58. bind . <Control-b> {puts stdout "Goodbye"}
  59. $m add cascade -label "Check buttons" \
  60.     -menu $w.menu.cascade.m.check -underline 0
  61. $m add cascade -label "Radio buttons" \
  62.     -menu $w.menu.cascade.m.radio -underline 0
  63.  
  64. set m $w.menu.cascade.m.check
  65. menu $m
  66. $m add check -label "Oil checked" -variable oil
  67. $m add check -label "Transmission checked" -variable trans
  68. $m add check -label "Brakes checked" -variable brakes
  69. $m add check -label "Lights checked" -variable lights
  70. $m add separator
  71. $m add command -label "Show current values" \
  72.     -command "showVars $w.menu.cascade.dialog oil trans brakes lights"
  73. $m invoke 1
  74. $m invoke 3
  75.  
  76. set m $w.menu.cascade.m.radio
  77. menu $m
  78. $m add radio -label "10 point" -variable pointSize -value 10
  79. $m add radio -label "14 point" -variable pointSize -value 14
  80. $m add radio -label "18 point" -variable pointSize -value 18
  81. $m add radio -label "24 point" -variable pointSize -value 24
  82. $m add radio -label "32 point" -variable pointSize -value 32
  83. $m add sep
  84. $m add radio -label "Roman" -variable style -value roman
  85. $m add radio -label "Bold" -variable style -value bold
  86. $m add radio -label "Italic" -variable style -value italic
  87. $m add sep
  88. $m add command -label "Show current values" \
  89.     -command "showVars $w.menu.cascade.dialog pointSize style"
  90. $m invoke 1
  91. $m invoke 7
  92.  
  93. set m $w.menu.icon.m
  94. menubutton $w.menu.icon -text "Icons" -menu $m -underline 0
  95. menu $m
  96. $m add command \
  97.     -bitmap @[file join $tk_library demos images pattern.bmp] \
  98.     -command {
  99.     tk_dialog .pattern {Bitmap Menu Entry} {The menu entry you invoked displays a bitmap rather than a text string.  Other than this, it is just like any other menu entry.} {} 0 OK
  100. }
  101. foreach i {info questhead error} {
  102.     $m add command -bitmap $i -command "puts {You invoked the $i bitmap}"
  103. }
  104.  
  105. set m $w.menu.more.m
  106. menubutton $w.menu.more -text "More" -menu $m -underline 0
  107. menu $m
  108. foreach i {{An entry} {Another entry} {Does nothing} {Does almost nothing} {Make life meaningful}} {
  109.     $m add command -label $i -command [list puts "You invoked \"$i\""]
  110. }
  111.  
  112. set m $w.menu.colors.m
  113. menubutton $w.menu.colors -text "Colors" -menu $m -underline 1
  114. menu $m
  115. foreach i {red orange yellow green blue} {
  116.     $m add command -label $i -background $i \
  117.         -command [list puts "You invoked \"$i\""]
  118. }
  119.  
  120. pack $w.menu.file $w.menu.basic $w.menu.cascade $w.menu.icon $w.menu.more \
  121.     $w.menu.colors -side left
  122.