Ruby + Tk 的 canvas 和形状有问题
Ruby + Tk's canvas and shapes are bugging out
我正在 运行ning Windows + Ruby2.3 并且正在弄乱 tk
库。我试图让它绘制一个由不同颜色的矩形组成的网格,但每当我尝试向 canvas 添加形状时,我的脚本就会崩溃。这是代码的精简版本:
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
然而,当我 运行 它时,我得到以下错误 + 回溯:
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>'
有人知道该怎么办吗?提前致谢。
我遇到了同样的错误,最后我通过添加下面的代码解决了这个问题:
module TkItemConfigOptkeys
def itemconfig_hash_kv(id, keys, enc_mode = [], conf = [])
hash_kv(__conv_item_keyonly_opts(id, keys), enc_mode, conf)
end
end
它应该在 '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
添加之后,我的代码运行得非常棒。
Ruby/Tk 已在 this commit 中修复此错误。
所以您可以只更新您的 tk 库,作为替代。
我正在 运行ning Windows + Ruby2.3 并且正在弄乱 tk
库。我试图让它绘制一个由不同颜色的矩形组成的网格,但每当我尝试向 canvas 添加形状时,我的脚本就会崩溃。这是代码的精简版本:
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
然而,当我 运行 它时,我得到以下错误 + 回溯:
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>'
有人知道该怎么办吗?提前致谢。
我遇到了同样的错误,最后我通过添加下面的代码解决了这个问题:
module TkItemConfigOptkeys
def itemconfig_hash_kv(id, keys, enc_mode = [], conf = [])
hash_kv(__conv_item_keyonly_opts(id, keys), enc_mode, conf)
end
end
它应该在 '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
添加之后,我的代码运行得非常棒。
Ruby/Tk 已在 this commit 中修复此错误。
所以您可以只更新您的 tk 库,作为替代。