how can i get the text of entry in TK?

S

slaughter

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
 
S

slaughter

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


I have resolve as this :)
 
M

Michael Morin

slaughter said:
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


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top