From: "Jeppe Jakobsen" <jeppe88 / gmail.com>
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 returns 0,
> when I add
> 
> puts var.value
> 
> to my code, just before Tk.mainloop?

???

---< var-test1.rb >----------------------------------------
require "tk"
var = TkVariable.new(0) #defining variable
var += 1 #making it a fixnum and adding 1

root = TkRoot.new()

label = TkLabel.new(:text=> var).pack()

button = TkButton.new(:text=> "Button", :command=>proc{var += 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 = TkVariable.new(0)
var.numeric += 1
label = TkLabel.new(:textvariable=>var).pack()
button = TkButton.new(:text=> "Button", :command=>proc{var.numeric += 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)