3
# sample script of Tk::OptionObj
7
optobj = Tk::OptionObj.new('foreground'=>'red', 'background'=>'black')
9
f = TkFrame.new.pack(:side=>:left, :anchor=>:n, :padx=>5, :pady=>30)
11
b1 = TkButton.new(f, :text=>'AAA').pack(:fill=>:x)
12
b2 = TkButton.new(f, :text=>'BBB').pack(:fill=>:x)
13
b3 = TkButton.new(f, :text=>'CCC').pack(:fill=>:x)
17
{ 'foreground'=>'background',
18
'background'=>'foreground' } ],
20
{ 'foreground'=>'background',
21
'activeforeground'=>nil,
22
'background'=>['foreground', 'activeforeground'] } ] )
24
optobj.update('activeforeground'=>'yellow')
27
configure( optobj.assign(self) + {:text=>'DDD'} )
32
configure( optobj.assign([self, nil,
33
{'foreground'=>'activeforeground',
34
'background'=>'foreground',
35
'activeforeground'=>'background'}]) \
36
+ {:text=>'EEE', :relief=>:groove, :borderwidth=>5} )
40
optobj.notify # To apply the convert_key ( 3rd element of widget info
41
# (that is, {'foreground'=>'activeforeground', ,,, } )
44
TkButton.new(f, :text=>'toggle',
46
fg = optobj['foreground']
47
bg = optobj['background']
48
optobj.configure('foreground'=>bg, 'background'=>fg)
49
}).pack(:fill=>:x, :pady=>10)
51
TkButton.new(f, :text=>'exit',
52
:command=>proc{exit}).pack(:fill=>:x, :pady=>10)
55
pack(:side=>:right, :expand=>true, :fill=>:both)
56
TkLabel.new(f, :text=>'source::').pack(:anchor=>:w)
59
yscrollbar(TkScrollbar.new(ff){pack(:fill=>:y, :side=>:right)})
60
insert('end', File.read(__FILE__))
61
pack(:side=>:left, :expand=>true, :fill=>:both)
63
pack(:expand=>true, :fill=>:both)