From: Mer Gilmartin <merrua / yahoo.co.uk> Subject: Re: Passing the data from a tkEntry widgit to a variable Date: Sat, 14 Oct 2006 00:01:34 +0900 Message-ID: <29004b56e98ed3a6904a59609e153d88 / ruby-forum.com> > Sample code for other newbies. > > @mytext = TkVariable.new('hi this is a test') > testtwo = TkEntry.new(Frameone, 'textvariable'=> @mytext) > { > puts value > } > > Value outputs whats been passed to the TkEntry widgit. > I think. ----<sample 1>-------------------------------------- mytext = @mytext = TkVariable.new('hi this is a test') testtwo = TkEntry.new(Frameone, 'textvariable'=> @mytext) { # self is the TkEntry widget self.bind('Button-1'){puts mytext.value} } ---------------------------------------------------- ----<sample 2>-------------------------------------- testtwo = TkEntry.new(Frameone) { self.value = 'hi this is a test' self.bind('Button-1'){puts self.value} } ---------------------------------------------------- ----<sample 3>-------------------------------------- @mytext = 'hi this is a test' testtwo = TkEntry.new(Frameone) testtwo.value = @mytext testtwo.bind('Button-1'){@mytext = testtwo.value; puts @mytext} ---------------------------------------------------- ----<sample 4>-------------------------------------- @mytext = 'hi this is a test' testtwo = TkEntry.new(Frameone) testtwo.value = @mytext callback = proc{@mytext = testtwo.value; puts @mytext} testtwo.bind('Button-1', callback) testtwo.bind('Return', callback) ---------------------------------------------------- ----<sample 5>-------------------------------------- @mytext = 'hi this is a test' testtwo = TkEntry.new(Frameone) testtwo.value = @mytext ev = TkVirtualEvent.new('Button-1', 'Return') testtwo.bind(ev){@mytext = testtwo.value; puts @mytext} ---------------------------------------------------- and so on. -- Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)