See sample scripts at ext/tk/samples directory of Ruby source archive.
If refer to ext/tk/samples/tktextframe.rb,
TkScrolledCanvas can be defined as such as the following.
---------------------------------------------------------------------
#!/usr/bin/env ruby
require 'tk'
class TkScrolledCanvas < TkCanvas
include TkComposite
def initialize_composite(keys={})
@h_scr = TkScrollbar.new(@frame)
@v_scr = TkScrollbar.new(@frame)
@canvas = TkCanvas.new(@frame)
@path = @canvas.path
@canvas.xscrollbar(@h_scr)
@canvas.yscrollbar(@v_scr)
TkGrid.rowconfigure(@frame, 0, :weight=>1, :minsize=>0)
TkGrid.columnconfigure(@frame, 0, :weight=>1, :minsize=>0)
@canvas.grid
row=>0, :column=>0, :sticky=>'news')
@h_scr.grid
row=>1, :column=>0, :sticky=>'ew')
@v_scr.grid
row=>0, :column=>1, :sticky=>'ns')
delegate('DEFAULT', @canvas)
delegate('background', @text, @h_scr, @v_scr)
delegate('activeforeground', @h_scr, @v_scr)
delegate('troughcolor', @h_scr, @v_scr)
delegate('repeatdelay', @h_scr, @v_scr)
delegate('repeatinterval', @h_scr, @v_scr)
delegate('borderwidth', @frame)
delegate('relief', @frame)
delegate_alias('canvasborderwidth', 'borderwidth', @canvas)
delegate_alias('canvasrelief', 'relief', @canvas)
delegate_alias('scrollbarborderwidth', 'borderwidth', @h_scr, @v_scr)
delegate_alias('scrollbarrelief', 'relief', @h_scr, @v_scr)
configure(keys) unless keys.empty?
end
end
c = TkScrolledCanvas.new
scrollregion=>[0,0,500,400]).pack
TkcRectangle.new(c, [100,100], [300, 200])
Tk.mainloop