Re: Scrolling a window

[email protected] (Jeff Hobbs)
Newsgroups perl.tcltk
Message-ID <[email protected]>
Hi David,

On 01/03/2010 2:37 PM, Swingle David-QWHM86 wrote:
> Hi, I'd like to scroll a window, but can't seem to get it work.  I've
> seen and tried code that scrolls widgets such as a listbox, but I want
> to scroll the entire window.  What I would prefer is that there be no
> scroll bars unless the user shrinks the window size so that widgets are
> now out of view.  First, I tried to associate the scrollbars with a
> frame, but I would get errors.  So, I tried using a canvas instead.  The
> code I have is below.  It will display scrollbars that do nothing.

I'm going to answer this from scratch again because the coffee hadn't 
kicked in the first time around and my answer was off.

For the lurking public, the scrolledwindow references ease the attaching 
and managing of auto-displaying scrollbars on scrollable windows.  It is 
part of what you (David) are actually looking for - the scrollable frame.

BWidget ScrollableFrame
http://docs.activestate.com/activetcl/8.5/bwidget/ScrollableFrame.html

This is the canvas-based widget which provides a way to scroll a 
collection of any other widgets as if in a frame.  You would wrap a 
ScrollableFrame in a ScrolledWindow for full effect, with a Tcl-based 
example at:

http://wiki.tcl.tk/1091 or http://wiki.tcl.tk/9924

converted to Tkx would be:

use strict;
use Tkx;
Tkx::package_require("BWidget");

my $mw = Tkx::widget->new(".");
my $sw = $mw->new_ScrolledWindow();
my $sf = $sw->new_ScrollableFrame();

$sw->g_pack(-fill => "both", -expand => 1);
$sw->setwidget($sf);

# This is the one tricky conversion.  We are getting a widget ref
# back from Tcl that has never been seen as a widget in Tkx, thus
# the Tkx::widget call makes the right kind of object.
my $subf = Tkx::widget->new($sf->getframe());

my $b;
for my $i (1..20) {
     for my $j (1..20) {
	$b = $subf->new_ttk__button(-text => "$i,$j",
				    -command => sub {exit;});
	$b->g_grid(-row => $i, -column => $j);
     }
}

Tkx::MainLoop;

Enjoy,

Jeff
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.