From: Noritsugu Nakamura Date: 1997-07-26T23:43:15+09:00 Subject: [ruby-list:3497] method of scroll (ruby/tk) 中村です。 ruby/tk の scroll について、いくつか。 1。 以下のようなプログラムを書いたのですが、 x 方向のスクロールバーの△を押すと、 xview なんてないと言われて終了してしまいます。 lib/ruby/tktext.rb を見ると xview がありません。 #!/usr/local/bin/ruby require "tkclass" TkButton.new { text 'QUIT' command 'exit' pack('side' => 'bottom', 'fill' => 'both') } text = xscroll = yscroll = nil xscroll = TkScrollbar.new { orient 'horizontal' command proc{|idx| text.xview *idx } pack('side' => 'bottom', 'fill' => 'x') } yscroll = TkScrollbar.new { command proc{|idx| text.yview *idx } pack('side' => 'right', 'fill' => 'y') } text = TkText.new { xscroll proc{|idx| xscroll.set *idx } yscroll proc{|idy| yscroll.set *idy } pack('side' => 'left') } Tk.mainloop 2。 lib/ruby/tkcanvas.rb の [xy]viewについて 以下のようなプログラムを書いたのですが (Python の Demo/tkinter/matt/ が題材です)、 スクロールバーの△を押すと、終了してしまいます。 lib/ruby/tkcanvas.rb の所、こうでしょうか? # いまだに * の意味分からないのですが (^^; def xview(*index) tk_send 'xview', *index end def yview(*index) tk_send 'yview', *index end あと、Canvas では xscroll を xscrollcommand とかにしないとダメみたいです。 #!/usr/local/bin/ruby require "tkclass" TkButton.new { text 'QUIT' background 'red' height 3 command 'exit' pack('side' => 'bottom', 'fill' => 'both') } canvas = xscroll = yscroll = nil xscroll = TkScrollbar.new { orient 'horizontal' command proc{|idx| canvas.xview *idx } pack('side' => 'bottom', 'fill' => 'x') } yscroll = TkScrollbar.new { command proc{|idx| canvas.yview *idx } pack('side' => 'right', 'fill' => 'y') } canvas = TkCanvas.new { width '5i' height '5i' background 'white' xscrollcommand proc{|idx| xscroll.set *idx } yscrollcommand proc{|idy| yscroll.set *idy } pack('side' => 'left') } Rectangle.new(canvas, 0, 0, '3.5i', '3.5i', 'fill' => 'black') Rectangle.new(canvas, '10i', '10i', '13.5i', '13.5i', 'fill' => 'black') Tk.mainloop 以上、よろしくお願いします。 中村典嗣 E-mail: nnakamur@mxq.meshnet.or.jp