Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based upon the additional code rkneufeld posted, this class requires a timer that is specific to Tk. To do it on the console, you could just create a loop that calls tick over and over. Of course, you have to remove all the code that was related to the GUI:</p> <pre><code>class Stopwatch def start @accumulated = 0 unless @accumulated @elapsed = 0 @start = Time.now # @mybutton.configure('text' =&gt; 'Stop') # @mybutton.command { stop } # @timer.start end def stop # @mybutton.configure('text' =&gt; 'Start') # @mybutton.command { start } # @timer.stop @accumulated += @elapsed end def reset stop @accumulated, @elapsed = 0, 0 # @mylabel.configure('text' =&gt; '00:00:00.00.000') end def tick @elapsed = Time.now - @start time = @accumulated + @elapsed h = sprintf('%02i', (time.to_i / 3600)) m = sprintf('%02i', ((time.to_i % 3600) / 60)) s = sprintf('%02i', (time.to_i % 60)) mt = sprintf('%02i', ((time - time.to_i)*100).to_i) ms = sprintf('%04i', ((time - time.to_i)*10000).to_i) ms[0..0]='' newtime = "#{h}:#{m}:#{s}.#{mt}.#{ms}" # @mylabel.configure('text' =&gt; newtime) end end watch = Stopwatch.new watch.start 1000000.times do puts watch.tick end </code></pre> <p>You'll end up with output like this:</p> <pre><code>00:00:00.00.000 00:00:00.00.000 00:00:00.00.000 ... 00:00:00.00.000 00:00:00.00.000 00:00:00.01.160 00:00:00.01.160 ... </code></pre> <p>Not particularly useful, but there it is. Now, if you're looking to do something similar in Shoes, try <a href="http://ruby.about.com/od/shoes/ss/shoes8.htm" rel="nofollow noreferrer">this tutorial</a> that is very similar.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload