From: SpringFlowers AutumnMoon Date: 2007-10-14T19:52:47+09:00 Subject: Re: how to use Ruby / Tk to display a text message status bo Morton Goldberg wrote: > On Sep 26, 2007, at 9:21 AM, Hidetoshi NAGAI wrote: > >> Tk.root.protocol(:WM_DELETE_WINDOW){ >> text.value = <> This is GUI #{(i / n)} >> Time is #{Time.now.strftime("%Y-%m-%d %I:%M:%S")} >> EOS >> printf "This is command line #{i / n}\n" >> end >> end This is one example with Tk.mainloop running as a thread, and a reporting loop running as a thread. I can't pass "i" into the report_and_sleep as "i" points to a constant instance of Fixnum. Needed to create a counter object so that a reference to the counter instance is passed, and the thread and extract the value from it: require 'tk' tk = TkRoot.new text = TkText.new(tk, 'width'=>80, "height" => 60).pack() class Counter attr_accessor :i end i = 0 n = 300000 counter = Counter.new() Tk.root.protocol(:WM_DELETE_WINDOW){ if Tk.messageBox(:type=>'okcancel', :message=>'Really exit? ') == 'ok' printf "Bye ...\n" exit else # ignore end } def report_and_sleep(text, counter) c = 0 time_start = Time.now while 1 c += 1 sleep 3 text.value = <