diff options
Diffstat (limited to 'ext/tk/sample/safe-tk.rb')
-rw-r--r-- | ext/tk/sample/safe-tk.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ext/tk/sample/safe-tk.rb b/ext/tk/sample/safe-tk.rb index 6b6de8f848..8be13a32d0 100644 --- a/ext/tk/sample/safe-tk.rb +++ b/ext/tk/sample/safe-tk.rb @@ -32,6 +32,7 @@ cmd = Proc.new{|txt| timer = TkTimer.new(50, -1, tick).start(0, proc{ label.text('0.00'); 0 }) +=begin TkButton.new(:text=>'Start') { command proc{ timer.continue unless timer.running? } pack(:side=>:left, :fill=>:both, :expand=>true) @@ -44,6 +45,30 @@ cmd = Proc.new{|txt| command proc{ timer.stop if timer.running? } pack('side'=>'right','fill'=>'both','expand'=>'yes') } +=end + b_start = TkButton.new(:text=>'Start', :state=>:disabled) { + pack(:side=>:left, :fill=>:both, :expand=>true) + } + b_stop = TkButton.new(:text=>'Stop', :state=>:normal) { + pack('side'=>'left', 'fill'=>'both', 'expand'=>'yes') + } + + b_start.command { + timer.continue + b_stop.state(:normal) + b_start.state(:disabled) + } + + b_stop.command { + timer.stop + b_start.state(:normal) + b_stop.state(:disabled) + } + + TkButton.new(:text=>'Reset', :state=>:normal) { + command { timer.reset } + pack('side'=>'right', 'fill'=>'both', 'expand'=>'yes') + } ev_quit = TkVirtualEvent.new('Control-c', 'Control-q') Tk.root.bind(ev_quit, proc{Tk.exit}).focus |