From: Jeppe Jakobsen Date: 2006-04-12T17:41:38+09:00 Subject: Re: Q about tk buttons ------=_Part_25_1845824.1144831293126 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks that kind of worked, but how come that the variable still returns 0, when I add puts var.value to my code, just before Tk.mainloop? 2006/4/12, Hidetoshi NAGAI : > > From: "Jeppe Jakobsen" > Subject: Q about tk buttons > Date: Wed, 12 Apr 2006 06:41:39 +0900 > Message-ID: <99b4ad3b0604111441p38d22688q14e03516af13db40@mail.gmail.com> > > Why can I use var +=3D 1 outside of the button, when I can't use it ins= ide > it. > > It means "var =3D var + 1". > "var + 1" returns 4, because TkVariable#+(obj) method expects > "numerical plus" when the arguemnt 'obj' is kind of Numeric. > And by setting the numeric value 4 to var, var losts the link > to the TkVariable object. > > Therefore, for example, > > > var =3D TkVariable.new(0) #defining variable > > var +=3D 1 #making it a fixnum and adding 1 > > var.value =3D var + 1 > or > var.numeric +=3D 1 > > > root =3D TkRoot.new() > > > > label =3D TkLabel.new(:text=3D> var).pack() > > label =3D TkLabel.new(:textvariable=3D>var).pack() > > > button =3D TkButton.new(:text=3D> "Button", :command=3D>proc{var +=3D 1= }).pack() > > button =3D TkButton.new(:text=3D> "Button", :command=3D>proc{var.value = =3D var + > 1}).pack() > or > button =3D TkButton.new(:text=3D> "Button", :command=3D>proc{var.numeric = +=3D > 1}).pack() > > -- > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) > > > -- "winners never quit, quitters never win" ------=_Part_25_1845824.1144831293126--