1# -*- coding: utf-8 -*- 2# 3# checkbutton widget demo (called by 'widget') 4# 5 6# toplevel widget が存在すれば削除する 7if defined?($check_demo) && $check_demo 8 $check_demo.destroy 9 $check_demo = nil 10end 11 12# demo 用の toplevel widget を生成 13$check_demo = TkToplevel.new {|w| 14 title("Checkbutton Demonstration") 15 iconname("check") 16 positionWindow(w) 17} 18 19base_frame = TkFrame.new($check_demo).pack(:fill=>:both, :expand=>true) 20 21# label 生成 22msg = TkLabel.new(base_frame) { 23 font $font 24 wraplength '4i' 25 justify 'left' 26 text "下には 3 つのチェックボタンが表示されています。クリックするとボタンの選択状態が変わり、Tcl 変数 ( TkVariable オブジェクトでアクセスできます ) にそのボタンの状態を示す値を設定します。現在の変数の値を見るには「変数参照」ボタンをクリックしてください。" 27} 28msg.pack('side'=>'top') 29 30# 変数生成 31wipers = TkVariable.new(0) 32brakes = TkVariable.new(0) 33sober = TkVariable.new(0) 34 35# frame 生成 36TkFrame.new(base_frame) {|frame| 37 TkButton.new(frame) { 38 #text '了解' 39 text '閉じる' 40 command proc{ 41 tmppath = $check_demo 42 $check_demo = nil 43 $showVarsWin[tmppath.path] = nil 44 tmppath.destroy 45 } 46 }.pack('side'=>'left', 'expand'=>'yes') 47 48 TkButton.new(frame) { 49 text 'コード参照' 50 command proc{showCode 'check'} 51 }.pack('side'=>'left', 'expand'=>'yes') 52 53 54 TkButton.new(frame) { 55 text '変数参照' 56 command proc{ 57 showVars(base_frame, 58 ['wipers', wipers], ['brakes', brakes], ['sober', sober]) 59 } 60 }.pack('side'=>'left', 'expand'=>'yes') 61 62}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') 63 64 65# checkbutton 生成 66[ TkCheckButton.new(base_frame, 'text'=>'ワイパー OK', 'variable'=>wipers), 67 TkCheckButton.new(base_frame, 'text'=>'ブレーキ OK', 'variable'=>brakes), 68 TkCheckButton.new(base_frame, 'text'=>'運転手 素面', 'variable'=>sober) 69].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')} 70 71