2

我在使用 Ruby/Tk 使用 ocra 创建独立程序时遇到问题。首先,这是一个简单的测试程序:

require 'tk'

hello = TkRoot.new do
  title "Test" minsize(100, 40)
end

TkLabel.new(hello) do
  text "Tk version is #{Tk::TK_PATCHLEVEL}"
  pack { padx 15; pady 15; side 'left'}
end

Tk.mainloop

如果单独运行,这将正常工作。

如果我运行ocra tk-test.rb,应用程序会按预期弹出,但是当它终止时,会发生未处理的异常:

$ ocra tk-test.rb
C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tk/font.rb:126:in `<class:TkFont>': unhandled exception
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tk/font.rb:9:in `<top (required)>'
        from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tk/fontchooser.rb:6:in `<top (required)>'
        from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:478:in `const_get'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:478:in `block (3 levels) in attempt_load_autoload'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:472:in `each'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:472:in `block (2 levels) in attempt_load_autoload'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:470:in `each'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:470:in `block in attempt_load_autoload'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:464:in `loop'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:464:in `attempt_load_autoload'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:723:in `build_exe'
        from C:/Ruby25/lib/ruby/gems/2.5.0/gems/ocra-1.3.10/bin/ocra:1203:in `block in <top (required)>'
=== Loading script to check dependencies
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::CheckButton
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Entry
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Frame
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::LabelFrame
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Listbox
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Menu
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Message
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::PanedWindow
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Scale
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Scrollbar
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Spinbox
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Text
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Toplevel
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Clock
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::OptionObj
=== Attempting to trigger autoload of #<Class:#<Tk::Label:0x02ef01b8>>::Fontchooser

Ruby 是使用带有 MSYS2 开发环境的 Rubyinstaller 安装的。

红宝石版本是:

RUBY VERSION: 2.5.3 (2018-10-18 patchlevel 105) [i386-mingw32]

已安装的 gem 版本为:

ocra (1.3.10)
tk (0.2.0)

谷歌搜索表明其他人也有类似的问题,但答案似乎都已过时或不适用。例如,这个答案 看起来很有希望,但是我的环境中没有这样的目录C:\Ruby25\lib\tcltk\,所以它不适用。

4

0 回答 0