How to define the height of a ScrollableFrame inside a ScrolledWindow?

140 views Asked by At

I want to put some (~30) CheckButtons inside a BWidget::ScrollableFrame which is located inside a BWidget::ScrolledWindow. For testing purposes I wanted to restrict the size of the ScrollableFrame to 100px by 100px. I expected a ScrollableFrame, sized 100x100, with the ability to scroll through all gridded CheckButtons, but the window is automatically extended so that all CheckButtons fit into the TkRoot.

Here's what I have tried:

#!/usr/bin/env ruby

require 'tk'
require 'tkextlib/bwidget'

class TestClass < TkRoot

    attr_reader :checkbutton

    def initialize(*args)
    minsize(800, 400)

    @checkbutton = []
    for i in 0..29
        @checkbutton.push({:name => "checkbutton #{i}"})
    end
    createGUI()
end

def createGUI       
    TkLabel.new(self, :text => 'first label').grid({:column => 0, :row => 0, :sticky => 'w'})

    scrolledwindow = Tk::BWidget::ScrolledWindow.new(self).grid({:column => 0, :row => 1, :sticky => 'w'})
    scrolledwindow.auto('none') # want to see if scrollbars are attached correctly

    scrollframe = Tk::BWidget::ScrollableFrame.new(scrolledwindow).grid({:column => 0, :row => 0, :sticky => 'w'})
    scrollframe.height(100)
    scrollframe.width(100)

    # leads to error: /usr/lib/ruby/1.9.1/tk.rb:215:in `class_eval': window name "frame" already exists in parent (RuntimeError)
    #sftest = scrollframe.get_frame

    scrolledwindow.set_widget(scrollframe)

    @checkbutton.each_with_index { |cb, index|
        TkCheckButton.new(scrollframe, :text => cb[:name]).grid({:column => 0, :row => index, :sticky => 'w'})
    }

    TkLabel.new(self, :text => 'second label').grid({:column => 1, :row => 0, :sticky => 'w'})
end
end

So... What's wrong? From what I saw here it should be possible to retrieve a frame with ScrollableFrame#get_frame, like this:

set a [$f getframe]

In ruby i would do it like this:

sftest = scrollframe.get_frame

The method get_frame doesn't exist in my installation. But my above ruby variant leads to the following error:

/usr/lib/ruby/1.9.1/tk.rb:215:in `class_eval': window name "frame" already exists in parent (RuntimeError)

I really have no clue why this error is thrown in this little script so I can't test if it's possible to configure the height and width at this widget. How can I set a fixed height and width for the ScrollableFrame?

Update: The size is set correctly as long as no CheckButton was added. The first time i add a CheckButton the ScrollableFrame is set to the size the CheckButtonneeds. How can i prevent resizing?

1

There are 1 answers

0
grandmasterg On BEST ANSWER

Ok... It seems that there's a problem with my used config, installation or compatibility.

I tried the following:

#!/usr/bin/env ruby1.8

Then no error is thrown and the folling line works:

sftest = scrollframe.get_frame

Now it's possible to add the CheckButtons to sftest and then i can scroll through a list of Checkbuttons...

greetz

gg