From: Jeppe Jakobsen Date: 2006-04-13T01:31:03+09:00 Subject: Re: Q about tk buttons ------=_Part_6946_449978.1144859459733 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Oh sorry I meant to say that it returns 1. If I click the button 29 times, the label shows 30, but the value that was puts'ed is still 1. 2006/4/12, Hidetoshi NAGAI : > > From: "Jeppe Jakobsen" > Subject: Re: Q about tk buttons > Date: Wed, 12 Apr 2006 17:41:38 +0900 > Message-ID: <99b4ad3b0604120141ha09eaacoa4b3a30bf18f9285@mail.gmail.com> > > Thanks that kind of worked, but how come that the variable still return= s > 0, > > when I add > > > > puts var.value > > > > to my code, just before Tk.mainloop? > > ??? > > ---< var-test1.rb >---------------------------------------- > require "tk" > var =3D TkVariable.new(0) #defining variable > var +=3D 1 #making it a fixnum and adding 1 > > root =3D TkRoot.new() > > label =3D TkLabel.new(:text=3D> var).pack() > > button =3D TkButton.new(:text=3D> "Button", :command=3D>proc{var +=3D 1})= .pack() > > puts var.value > > Tk.mainloop > ----------------------------------------------------------- > > $ /usr/local/bin/ruby -v > ruby 1.8.4 (2006-04-06) [i686-linux] > $ /usr/local/bin/ruby var-test1.rb > var-test1.rb:11: undefined method `value' for 1:Fixnum (NoMethodError) > > > ---< var-test2.rb >---------------------------------------- > require "tk" > var =3D TkVariable.new(0) > var.numeric +=3D 1 > label =3D TkLabel.new(:textvariable=3D>var).pack() > button =3D TkButton.new(:text=3D> "Button", :command=3D>proc{var.numeric = +=3D > 1}).pack() > puts var.value > Tk.mainloop > ----------------------------------------------------------- > > $ /usr/local/bin/ruby -v > ruby 1.8.4 (2006-04-06) [i686-linux] > $ /usr/local/bin/ruby var-test2.rb > 1 > $ > > -- > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) > > -- "winners never quit, quitters never win" ------=_Part_6946_449978.1144859459733--