From: Phlip <phlip2005 / gmail.com>
Subject: Re: A Tk window
Date: Tue, 3 Feb 2009 22:54:48 +0900
Message-ID: <kZXhl.11748$W06.4001 / flpi148.ffdc.sbc.com>

> > Cheat, override the 'close' button and make it hide the window instead?

Tk.root.protocol('WM_DELETE_WINDOW'){Tk.root.withdraw}

> Then the Tk.mainloop keeps ticking, meaning you have to then slice up your outer 
> algorithm and put it in a timer, etc. etc.!!

There is a trick ;-)
-----------------------------------------------------------
require 'tk'

class MyWin
  def initialize
    @v = TkVariable.new
    r = Tk.root
    r.protocol('WM_DELETE_WINDOW'){r.withdraw; Tk.update; @v.value = 1}
    TkButton.new(:text=>'TEST', :command=>proc{puts 'running!'}).pack
  end

  def start_eventloop
    Tk.root.deiconify
    @v.wait  # wait command makes a eventloop while waiting
  end
end

w = MyWin.new
5.times{
  w.start_eventloop
  p Thread.list
  sleep 3
}
-----------------------------------------------------------
-- 
Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)