1# button.rb 2# 3# This demonstration script creates a toplevel window containing 4# several button widgets. 5# 6# button widget demo (called by 'widget') 7# 8 9# toplevel widget 10if defined?($button_demo) && $button_demo 11 $button_demo.destroy 12 $button_demo = nil 13end 14 15# demo toplevel widget 16$button_demo = TkToplevel.new {|w| 17 title("Button Demonstration") 18 iconname("button") 19 positionWindow(w) 20} 21 22# label 23msg = TkLabel.new($button_demo) { 24 font $kanji_font 25 wraplength '4i' 26 justify 'left' 27 text "If you click on any of the four buttons below, the background of the button area will change to the color indicated in the button. You can press Tab to move among the buttons, then press Space to invoke the current button." 28} 29msg.pack('side'=>'top') 30 31# frame 32$button_buttons = Tk::Frame.new($button_demo) {|frame| 33 TkButton.new(frame) { 34 text 'Dismiss' 35 command proc{ 36 tmppath = $button_demo 37 $button_demo = nil 38 tmppath.destroy 39 } 40 }.pack('side'=>'left', 'expand'=>'yes') 41 42 TkButton.new(frame) { 43 text 'See Code' 44 command proc{showCode 'button'} 45 }.pack('side'=>'left', 'expand'=>'yes') 46 47}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') 48 49# button 50TkButton.new($button_demo){ 51 text "Peach Puff" 52 width 10 53 command proc{ 54 $button_demo.configure('bg','PeachPuff1') 55 $button_buttons.configure('bg','PeachPuff1') 56 } 57}.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2) 58 59TkButton.new($button_demo){ 60 text "Light Blue" 61 width 10 62 command proc{ 63 $button_demo.configure('bg','LightBlue1') 64 $button_buttons.configure('bg','LightBlue1') 65 } 66}.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2) 67 68TkButton.new($button_demo){ 69 text "Sea Green" 70 width 10 71 command proc{ 72 $button_demo.configure('bg','SeaGreen2') 73 $button_buttons.configure('bg','SeaGreen2') 74 } 75}.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2) 76 77TkButton.new($button_demo){ 78 text "Yellow" 79 width 10 80 command proc{ 81 $button_demo.configure('bg','Yellow1') 82 $button_buttons.configure('bg','Yellow1') 83 } 84}.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2) 85