1

Ruby / Tkにペインウィンドウを追加しようとすると、次のエラーが発生します。

C:/Users/user/Ruby193/lib/ruby/1.9.1/tk.rb:3016:in `_invoke': Attempt to change read-only option (RuntimeError)

次のように、コードにorientオプションを追加するたびに:

p = Tk::Tile::Paned.new(parent) { orient 'horizontal' }

何らかの理由で「orient」は読み取り専用(デフォルトは「vertical」)になっているようです。ペインウィンドウの例を含むWeb上のruby/tkチュートリアルに気づきましたが、おそらく同じエラーが発生したために、orientオプションの使用を避けましたか?

次のチュートリアルコードを.rbファイルに貼り付けて実行すると(方向付けオプションなし)、機能します。上記のようなorientオプションを追加すると、失敗します。

require 'tk'
require 'tkextlib/tile'

$resultsVar = TkVariable.new
root = TkRoot.new
root.title = "Window"

p = Tk::Tile::Paned.new(root)do
  height 110
  place('height' => 100, 'width' => 200, 'x' => 10, 'y' => 10)
  #orient 'horizontal' # <== uncomment this line to see error
end

f1 = TkFrame.new(p) {
  relief 'groove'
  borderwidth 3
  background "red"
  padx 30
  pady 30
  pack('side' => 'left', 'pady' => 100)
}
f2 = TkFrame.new (p){
  relief 'groove'
  borderwidth 3
  background "yellow"
  padx 30
  pady 30
  pack('side' => 'right', 'pady' => 100)
}

p.add f1 #, nil <== had to remove nil option here because this also caused an error
p.add f2 #, nil

Tk.mainloop

他の誰かが「オリエント」オプションを機能させることができましたか?デフォルトの垂直値ではなく、水平にする必要があります。tk.rbを見て、エラートレースをたどってみましたが、「method_missing」の問題を示しているようです。

4

1 に答える 1