From: Hidetoshi NAGAI Date: 2006-04-12T11:27:13+09:00 Subject: Re: Q about tk buttons 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 += 1 outside of the button, when I can't use it inside it. It means "var = 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 = TkVariable.new(0) #defining variable > var += 1 #making it a fixnum and adding 1 var.value = var + 1 or var.numeric += 1 > root = TkRoot.new() > > label = TkLabel.new(:text=> var).pack() label = TkLabel.new(:textvariable=>var).pack() > button = TkButton.new(:text=> "Button", :command=>proc{var += 1}).pack() button = TkButton.new(:text=> "Button", :command=>proc{var.value = var + 1}).pack() or button = TkButton.new(:text=> "Button", :command=>proc{var.numeric += 1}).pack() -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)