所以我有这个应用程序
require 'tk'
class Foo
def my_fancy_function
puts "hello, world!"
end
def initialize
@root = TkRoot.new{title "Hello, world!"}
frame = TkFrame.new
my_fancy_button = TkButton.new(frame) do
text "Press meee"
command {my_fancy_function}
pack
end
frame.pack
Tk.mainloop
end
end
bar = Foo.new
但如果我按下按钮,我会得到“nameerror:undefined local variable or method‘my-fabric’for<tkbutton:”
我很肯定我遗漏了一些与示波器有关的琐碎的东西…如何将该命令正确绑定到按钮?
编辑:好的,如果我改变我的
my_fancy_button
阻止参数,即
my_fancy_button = TkButton.new(frame, :text => "Press meee", :command => proc{my_fancy_function}).pack
然后它工作。但是为什么呢?