Forum: Ruby how can i get the text of entry in TK?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ce55d087759c1f7fe4a1c4f6cf4bc745?d=identicon&s=25 qd zheng (slaughter)
on 2008-11-07 07:10
(Received via mailing list)
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
5316d692cc603c3ad2df0f03869bb96b?d=identicon&s=25 Michael Morin (Guest)
on 2008-11-07 20:40
(Received via mailing list)
slaughter wrote:
>  }
>   command{
>      puts a.cget('text')
>
>   }
> }
>
> Tk.mainloop
>
>
>


Here is a working example.

http://ruby.about.com/od/tk/ss/widgets_6.htm

You used the method cget, I believe the correct method is value.
This topic is locked and can not be replied to.