C
chen1069osu
Hi all,
I am new to tk. I try to build a simple GUI with several widgets following the tutorials from this website:http://www.tkdocs.com/tutorial/widgets.html#checkbutton
One of the widgets I copy from website is checkbutton as following:
require 'tk'
require 'tkextlib/tile'
root = TkRoot.new {title "Feet to Meters"}
$measureSystem = TkVariable.new
check = Tk::Tile::CheckButton.new(root) {
text 'Use Metric';
command 'metricChanged';
variable $measureSystem;
onvalue 'metric';
offvalue 'imperial';
pack
}
Tk.mainloop
when I check the checkbutton, I get an error message as following:
NameError: undefined local variable or method `metricChanged' for main:Object
---< backtrace of Ruby side >-----
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1456:in `cb_eval'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1456:in `eval_cmd'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1456:in `cb_eval'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1403:in `call'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1599:in `block in callback'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1598:in `catch'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1598:in `callback'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1305:in `mainloop'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1305:in `block in <module:TkCore>'
---< backtrace of Tk side >-------
invoked from within
"rb_out c00001"
invoked from within
".w00000 invoke "
invoked from within
".w00000 instate !disabled { .w00000 invoke } "
invoked from within
".w00000 instate pressed { .w00000 state !pressed; .w00000 instate !disabled { .w00000 invoke } } "
(command bound to event)
so my question is that why this happens? How come I cannot set the check or uncheck from user end or set its status interactively?
Thank you so much in advance for your help.
I am new to tk. I try to build a simple GUI with several widgets following the tutorials from this website:http://www.tkdocs.com/tutorial/widgets.html#checkbutton
One of the widgets I copy from website is checkbutton as following:
require 'tk'
require 'tkextlib/tile'
root = TkRoot.new {title "Feet to Meters"}
$measureSystem = TkVariable.new
check = Tk::Tile::CheckButton.new(root) {
text 'Use Metric';
command 'metricChanged';
variable $measureSystem;
onvalue 'metric';
offvalue 'imperial';
pack
}
Tk.mainloop
when I check the checkbutton, I get an error message as following:
NameError: undefined local variable or method `metricChanged' for main:Object
---< backtrace of Ruby side >-----
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1456:in `cb_eval'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1456:in `eval_cmd'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1456:in `cb_eval'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1403:in `call'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1599:in `block in callback'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1598:in `catch'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1598:in `callback'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1305:in `mainloop'
C:/Ruby200-x64/lib/ruby/2.0.0/tk.rb:1305:in `block in <module:TkCore>'
---< backtrace of Tk side >-------
invoked from within
"rb_out c00001"
invoked from within
".w00000 invoke "
invoked from within
".w00000 instate !disabled { .w00000 invoke } "
invoked from within
".w00000 instate pressed { .w00000 state !pressed; .w00000 instate !disabled { .w00000 invoke } } "
(command bound to event)
so my question is that why this happens? How come I cannot set the check or uncheck from user end or set its status interactively?
Thank you so much in advance for your help.