From: Hidetoshi NAGAI Date: 2009-05-18T00:24:28+09:00 Subject: Re: Ruby/Tk From: Oleg Igor Subject: Re: Ruby/Tk Date: Sun, 17 May 2009 18:55:47 +0900 Message-ID: <9a4197f4c584ffc1c50449c46246739d@ruby-forum.com> > I not found -textvariable options in TkText :( If you use Tcl/Tk8.5, Tk::Text::Peer widget is useful. ---------------------------------------------------------------------- txt = Tk::Text.new # A base text widget. # In this case, it isn't shown on the GUI. top = Tk::Toplevel.new peer = Tk::Text::Peer.new(txt, top).pack # A peer widget of 'txt' widget. Its parent is 'top' widget. # ... destroy 'top' widget ... p txt.value # This is the same content with the destroyed peer. ---------------------------------------------------------------------- If you use Tcl/Tk8.4 or the former version, you can "withdraw" the dialog instead of "destroy". ---------------------------------------------------------------------- top = Tk::Toplevel.new txt = Tk::Text.new(top).pack @value = "" top.protocol('WM_DELETE_WINDOW'){ top.withdraw; @value = txt.value } # Ignore 'WM_DELETE_WINDOW' protocol (e.g. when click the 'delete' # button on the window frame) from a window manager. # In this case, withdraw the toplevel widget instead of destroy it. # ... withdraw the toplevel ... p @value top.deiconify # Display the toplevel widget in normal form. ---------------------------------------------------------------------- Or, get value before destroying the toplevel. ---------------------------------------------------------------------- top = Tk::Toplevel.new txt = Tk::Text.new(top).pack @value = "" top.protocol('WM_DELETE_WINDOW'){ @value = txt.value; top.destroy } # ... destroy the toplevel ... p @value ---------------------------------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)