how can i get the text of entry in TK? - RUBY

This is a discussion on how can i get the text of entry in TK? - RUBY ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

how can i get the text of entry in TK?

  1. Default how can i get the text of entry in TK?

    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



  2. Default Re: how can i get the text of entry in TK?

    On 11月7日, 下午2时08分, slaughter <fz...@hotmail.com> wrote:
    > 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


    > require 'tk'
    >
    > root=TkRoot.new{
    > title "getValue"
    > }
    >
    > var=TkVariable.new
    > a=TkEntry.new(root){
    > grid 'row'=>1,'column'=>1
    > }


    a.textvariable=var

    > TkButton.new(root){
    > text "get"
    > grid 'row'=>3,'column'=>1
    > command{
    > puts a.cget('textvariable')
    >
    > }
    >
    > }
    >
    > Tk.mainloop


  3. Default Re: how can i get the text of entry in TK?

    slaughter wrote:
    > 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.


+ Reply to Thread