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
@test = TestClass.new
@test.mainloop
So… What’s wrong? Why it isn’t restricted to 100x100 pixel and
scrollable? From what I 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?