1# check.rb
2#
3# This demonstration script creates a toplevel window containing
4# several checkbuttons.
5#
6# checkbutton widget demo (called by 'widget')
7#
8
9# toplevel widget
10if defined?($check_demo) && $check_demo
11  $check_demo.destroy
12  $check_demo = nil
13end
14
15# demo toplevel widget
16$check_demo = TkToplevel.new {|w|
17  title("Checkbutton Demonstration")
18  iconname("check")
19  positionWindow(w)
20}
21
22base_frame = TkFrame.new($check_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 "Three checkbuttons are displayed below.  If you click on a button, it will toggle the button's selection state and set a Tcl variable to a value indicating the state of the checkbutton.  Click the \"See Variables\" button to see the current values of the variables."
30}
31msg.pack('side'=>'top')
32
33#
34wipers = TkVariable.new(0)
35brakes = TkVariable.new(0)
36sober  = TkVariable.new(0)
37
38# frame
39TkFrame.new(base_frame) {|frame|
40  TkButton.new(frame) {
41    text 'Dismiss'
42    command proc{
43      tmppath = $check_demo
44      $check_demo = nil
45      $showVarsWin[tmppath.path] = nil
46      tmppath.destroy
47    }
48  }.pack('side'=>'left', 'expand'=>'yes')
49
50  TkButton.new(frame) {
51    text 'Show Code'
52    command proc{showCode 'check'}
53  }.pack('side'=>'left', 'expand'=>'yes')
54
55
56  TkButton.new(frame) {
57    text 'See Variables'
58    command proc{
59      showVars(base_frame,
60               ['wipers', wipers], ['brakes', brakes], ['sober', sober])
61    }
62  }.pack('side'=>'left', 'expand'=>'yes')
63
64}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
65
66
67# checkbutton
68[ TkCheckButton.new(base_frame, 'text'=>'Wipers  OK', 'variable'=>wipers),
69  TkCheckButton.new(base_frame, 'text'=>'Brakes  OK', 'variable'=>brakes),
70  TkCheckButton.new(base_frame, 'text'=>'Driver Sober', 'variable'=>sober)
71].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')}
72
73