diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-06-21 12:55:17 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-06-21 12:55:17 +0000 |
commit | 07cff4bd71d4d71e4901aac5df11746ce96f009b (patch) | |
tree | 27d9b56f85b13be8924e56ccc1f6009d5bd666d9 /ext/tk/sample | |
parent | 818157eae67c00be5610ce6e9488d448009a40ba (diff) |
tk.rb :
* TkRoot.new and TkToplevel.new accept Wm commands as elements
of a hash argument.
e.g. TkRoot.new(:title=>'App Title')
TkToplevel.new(:parent=>Tk.root, :title=>'XXX', :class=>'ZZZ')
sample/tktimer2.rb
* add comments about the usage of a TkTimer object.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
-rw-r--r-- | ext/tk/sample/tktimer2.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ext/tk/sample/tktimer2.rb b/ext/tk/sample/tktimer2.rb index 0359ac4d08..dc4e8a6964 100644 --- a/ext/tk/sample/tktimer2.rb +++ b/ext/tk/sample/tktimer2.rb @@ -3,16 +3,30 @@ require "tk" -label = TkLabel.new(:relief=>:raised, :width=>10) \ +# new notation : +# * symbols are acceptable as keys or values of the option hash +# * the parent widget can be given by :parent key on the option hash +root = TkRoot.new(:title=>'timer sample') +label = TkLabel.new(:parent=>root, :relief=>:raised, :width=>10) \ .pack(:side=>:bottom, :fill=>:both) -tick = proc{|aobj| - cnt = aobj.return_value + 5 +# define the procedure repeated by the TkTimer object +tick = proc{|aobj| #<== TkTimer object + cnt = aobj.return_value + 5 # return_value keeps a result of the last proc label.text format("%d.%02d", *(cnt.divmod(100))) - cnt + cnt #==> return value is kept by TkTimer object + # (so, can be send to the next repeat-proc) } timer = TkTimer.new(50, -1, tick).start(0, proc{ label.text('0.00'); 0 }) + # ==> repeat-interval : (about) 50 ms, + # repeat : infinite (-1) times, + # repeat-procedure : tick (only one, in this case) + # + # ==> wait-before-call-init-proc : 0 ms, + # init_proc : proc{ label.text('0.00'); 0 } + # + # (0ms)-> init_proc ->(50ms)-> tick ->(50ms)-> tick ->.... TkButton.new(:text=>'Start') { command proc{ timer.continue unless timer.running? } |