Ruby + Tk的画布和形状出现问题

not*_*560 3 ruby tk-toolkit

我正在运行Windows + Ruby2.3,并弄乱了该tk库。我试图使其绘制不同颜色的矩形网格,但是每当我尝试向画布添加形状时,脚本都会崩溃。这是简化的代码版本:

require 'tk'
require 'tkextlib/tile'
root = TkRoot.new
content = Tk::Tile::Frame.new(root)
canvas = TkCanvas.new(content)
line = TkcLine.new( canvas, 0, 0, 10, 10, :fill => 'red' )
Tk.mainloop
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,出现以下错误+回溯:

C:/Ruby23/lib/ruby/2.3.0/tk/itemconfig.rb:115:in `hash_kv': wrong argument type nil (expected Array) (TypeError)
        from C:/Ruby23/lib/ruby/2.3.0/tk/itemconfig.rb:115:in `itemconfig_hash_kv'
        from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:722:in `_parse_create_args'
        from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:735:in `create'
        from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:758:in `create_self'
        from C:/Ruby23/lib/ruby/2.3.0/tk/canvas.rb:751:in `initialize'
        from C:/nopathforyou.rb:9:in `new'
        from C:/nopathforyou.rb:9:in `<main>'
Run Code Online (Sandbox Code Playgroud)

有人知道该怎么办吗?提前致谢。

ice*_*000 5

我遇到了相同的错误,最后通过添加以下代码解决了这个问题:

module TkItemConfigOptkeys
    def itemconfig_hash_kv(id, keys, enc_mode = [], conf = [])
        hash_kv(__conv_item_keyonly_opts(id, keys), enc_mode, conf)
    end
end
Run Code Online (Sandbox Code Playgroud)

应该在“ require”语句之后,例如,您的代码应类似于:

require 'tk'
require 'tkextlib/tile'
module TkItemConfigOptkeys
  def itemconfig_hash_kv(id, keys, enc_mode = [], conf = [])
    hash_kv(__conv_item_keyonly_opts(id, keys), enc_mode, conf)
  end
end
root = TkRoot.new
content = Tk::Tile::Frame.new(root)
canvas = TkCanvas.new(content)
line = TkcLine.new( canvas, 0, 0, 10, 10, :fill => 'red' )
Tk.mainloop
Run Code Online (Sandbox Code Playgroud)

添加之后,我的代码就像一个魅力。