Hi !

I have a trouble.

require “tk”

class Main
def initialize
@root = { title “prog” }

top =
@edit = {

cmd = proc { puts @edit.get }

button = {
text “”
command cmd


m =

How to get @edit value after “top” is closed ?


How to get @edit value after “top” is closed ?

If I remember correctly you need to use @edit.value



From: “removed_email_address@domain.invalid” removed_email_address@domain.invalid
Subject: Ruby/Tk
Date: Fri, 15 May 2009 23:45:07 +0900

How to get @edit value after “top” is closed ?

One of the simple solution is to use a TkVariable and
‘textvariable’ option of an entry widget.


I not found -textvariable options in TkText :frowning:


From: Oleg I. removed_email_address@domain.invalid
Subject: Re: Ruby/Tk
Date: Sun, 17 May 2009 18:55:47 +0900
Message-ID: removed_email_address@domain.invalid

I not found -textvariable options in TkText :frowning:

If you use Tcl/Tk8.5, Tk::Text::Peer widget is useful.

txt = # A base text widget.
# In this case, it isn’t shown on the GUI.

top =
peer =, 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 =
txt =
@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 =
txt =
@value = “”
top.protocol(‘WM_DELETE_WINDOW’){ @value = txt.value; top.destroy }

… destroy the toplevel …

p @value