# How can i get the text of entry in TK?

**URL:** <https://www.ruby-forum.com/t/how-can-i-get-the-text-of-entry-in-tk/152758>\
**Category:** Ruby\
**Created:** [November 7, 2008, 7:10am UTC](https://www.ruby-forum.com/t/how-can-i-get-the-text-of-entry-in-tk/152758 "2008-11-07T07:10:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![slaughter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@slaughter](https://www.ruby-forum.com/u/slaughter)\
**Post date:** [November 7, 2008, 7:10am UTC](https://www.ruby-forum.com/t/how-can-i-get-the-text-of-entry-in-tk/152758/1 "2008-11-07T07:10:50Z")

</div>

hi everyone!  
I want to get the text of entry in TK,when run the script,I input  
the value “test” in the entry,but click the button “get”,It just show  
the value “Null”,not the value “test” which is except.  
what is the wrong? the script is as below:

require ‘tk’

root=TkRoot.new{  
title “getValue”  
}

var=TkVariable.new  
a=TkEntry.new(root){  
text=var  
grid ‘row’=\>1,‘column’=\>1  
}

TkButton.new(root){  
text “get”  
grid ‘row’=\>3,‘column’=\>1  
command{  
puts a.cget(‘text’)

}  
}

Tk.mainloop

---

<div class="post-metadata">

**Author:** ![slaughter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@slaughter](https://www.ruby-forum.com/u/slaughter)\
**Post date:** [November 7, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/how-can-i-get-the-text-of-entry-in-tk/152758/2 "2008-11-07T20:40:32Z")

</div>

slaughter wrote:

> }  
> command{  
> puts a.cget(‘text’)
> 
> }  
> }
> 
> Tk.mainloop

Here is a working example.

> **[How to Install and Use Ruby's Tk Toolkit](https://www.thoughtco.com/installing-tk-gui-toolkit-2908365)**
>
> The Tk GUI toolkit was originally written for the TCL scripting language but has since been adopted by many other languages including Ruby.

You used the method cget, I believe the correct method is value.
