お世話になっております
コードで ボタンをクリックすると
NameError: unknown option 'test3' for #<Tk::Button:0x0000000004f951b0 @path=".w00000.w00001"> (deleted widget?)
---< backtrace of Ruby side >-----
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:4984:in rescue in method_missing' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:4980:in
method_missing'
(eval):1:in block (2 levels) in initialize' f:/files/tempCodeRunnerFile.ruby:20:in
eval'
f:/files/tempCodeRunnerFile.ruby:20:in block (2 levels) in initialize' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1456:in
eval_cmd'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1456:in cb_eval' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1403:in
call'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1607:in block in callback' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1606:in
catch'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1606:in callback' C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1301:in
mainloop'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/tk-0.2.0/lib/tk.rb:1301:in `block in module:TkCore'
---< backtrace of Tk side >-------
invoked from within
"rb_out c00001"
invoked from within
".w00000.w00001 invoke"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list $w invoke]"
(procedure "tk::ButtonUp" line 24)
invoked from within
"tk::ButtonUp .w00000.w00001"
(command bound to event)
と 出ます
Ruby
1require 'tk' 2require 'tkafter' 3 4class Display 5 def initialize 6 ph = { 'padx' => 10, 'pady' => 10 } 7 @myFont = TkFont.new("family" => 'Helvetica',"size" => 13,"weight" => 'bold') 8 9 @text1 = TkVariable.new 10 @text2 = TkVariable.new 11 @text3 = TkVariable.new 12 @text4 = TkVariable.new 13 14 @root = TkRoot.new 15 @root.geometry = "100x100+75+0" 16 @top = TkFrame.new(@root , 'background' => '#FFFFF7') 17 18 #eval("test3()") 19 TkButton.new(@top) {text 'Exit'; command proc { eval("test3()")}; pack ph} 20 @top.pack('fill'=>'both', 'side' =>'top') 21 22 show 23 24 end 25 26 def show() 27 @root.mainloop 28 end 29 30 def test() 31 print ('OK!') 32 end 33 34 def test2() 35 print ('OK!!') 36 end 37 38 def test3() 39 eval ("test()") 40 eval ("test2()") 41 exit 42 end 43 44end 45 46 47 48Display.new
TkButton.new(@top) {text 'Exit'; command proc { eval("test3()")}; pack ph}
で ボタンを押すと 関数が 実行されるようにしたいのですが
どのような修正を すれば よいのでしょうか?
TkButton.new(@top) {text 'Exit'; command proc { test3()}; pack ph}
も試しましたが やはりエラーが発生します
ご教示の程よろしくお願い致します

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/04 22:55