1# radio.rb 2# 3# This demonstration script creates a toplevel window containing 4# several radiobutton widgets. 5# 6# radiobutton widget demo (called by 'widget') 7# 8 9# toplevel widget 10if defined?($radio_demo) && $radio_demo 11 $radio_demo.destroy 12 $radio_demo = nil 13end 14 15# demo toplevel widget 16$radio_demo = TkToplevel.new {|w| 17 title("Radiobutton Demonstration") 18 iconname("radio") 19 positionWindow(w) 20} 21 22base_frame = TkFrame.new($radio_demo).pack(:fill=>:both, :expand=>true) 23 24# label 25msg = TkLabel.new(base_frame) { 26 font $font 27 wraplength '4i' 28 justify 'left' 29 text "Two groups of radiobuttons are displayed below. If you click on a button then the button will become selected exclusively among all the buttons in its group. A Tcl variable is associated with each group to indicate which of the group's buttons is selected. Click the \"See Variables\" button to see the current values of the variables." 30} 31msg.pack('side'=>'top') 32 33# 34size = TkVariable.new 35color = TkVariable.new 36 37# frame 38TkFrame.new(base_frame) {|frame| 39 TkButton.new(frame) { 40 text 'Dismiss' 41 command proc{ 42 tmppath = $radio_demo 43 $radio_demo = nil 44 $showVarsWin[tmppath.path] = nil 45 tmppath.destroy 46 } 47 }.pack('side'=>'left', 'expand'=>'yes') 48 49 TkButton.new(frame) { 50 text 'Show Code' 51 command proc{showCode 'radio'} 52 }.pack('side'=>'left', 'expand'=>'yes') 53 54 TkButton.new(frame) { 55 text 'See Variables' 56 command proc{ 57 showVars(base_frame, ['size', size], ['color', color]) 58 } 59 }.pack('side'=>'left', 'expand'=>'yes') 60}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') 61 62# frame 63f_left = TkFrame.new(base_frame) 64f_right = TkFrame.new(base_frame) 65f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') 66f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') 67 68# radiobutton 69[10, 12, 18, 24].each {|sz| 70 TkRadioButton.new(f_left) { 71 text "Point Size #{sz}" 72 variable size 73 relief 'flat' 74 value sz 75 }.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w') 76} 77 78['Red', 'Green', 'Blue', 'Yellow', 'Orange', 'Purple'].each {|col| 79 TkRadioButton.new(f_right) { 80 text col 81 variable color 82 relief 'flat' 83 value col.downcase 84 }.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w') 85} 86 87