Commy_Code_Monkey has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to put scrolling widgets within a scrolling frame. I want to make it so my many widgets will all be visible by scrolling, should the app be opened on a computer with lower resolution. Now, it seems that Frame() does not support scrolling, so I am instead using a Scrolled Pane. Within the scrolled pane I can display unscrolled widgets... but scrolled widgets do not work. Am I doing something obviously wrong? I'm relatively new to perl and Tk, so go easy on me.
my $mw = MainWindow->new; $mw->geometry("1200x850"); my $p = $mw->Scrolled('Pane', -scrollbars => 'se', -width=>'1200', -height=>'850' )->pack; my $listbox1=$p->Scrolled('Listbox', -scrollbars=>'e', -exportselection => 0 )->place(-anchor=>'nw', -x=>"50", -y=>"150"); $listbox1->configure(-height=>'35', -width=>'25', -selectmode => "browse");

Replies are listed 'Best First'.
Re: Scrolled within a Scrolled
by Sandy (Curate) on Nov 28, 2008 at 18:22 UTC
    This works for me on Windows and Solaris (perl 5.8.8)
    use strict; use Tk; my $mw = MainWindow->new; $mw->geometry("1200x850"); my $p = $mw->Scrolled('Pane', -scrollbars => 'se', -width=>'1200', -height=>'850' )->pack; my $listbox1=$p->Scrolled('Listbox', -scrollbars=>'e', -exportselection => 0 )->place(-anchor=>'nw', -x=>"50", -y=>"150"); $listbox1->configure(-height=>'35', -width=>'25', -selectmode => "browse"); $listbox1->insert('end',1..150); MainLoop();
    Is it perhaps because you forgot the MainLoop() ??
      Interesting... as a separate file it also works for me... But in with the rest of my code, the scrolled listboxes still refuse to show up. (No I did not forget MainLoop, but I'd ask me that too) If I change $listbox1 to a non-scrolled widget... it displays. ie...
      #my $listbox1=$p->Scrolled('Listbox', # -scrollbars=>'e', # -exportselection => 0 # )->place(-anchor=>'nw', # -x=>"50", # -y=>"150"); my $listbox1=$p->Listbox()->place(-anchor=>'nw',-x=>"50",-y=>"150"); + $listbox1->configure(-height=>'35', -width=>'25', -selectmode => " +browse");
      It just does NOT like the scrolled option. I'm running ActivePerl 5.10.0.1004 on a WinXP machine btw.
      AFter some additional tinkering and even more swearing... I've found that the Pane widget, doesn't actually act like a scrolled frame as the docs said. They apparently have a limit on how many scrolled widgets they can contain. That's why my example code works... and my actual code did not. I was able to bypass this problem by specifying a new frame for each scrolled widget in the pane. Is there a subroutine to get those 4 hours of my life back...?
      my $p = $mw->Scrolled('Pane', -scrollbars => 'se', -width=>'1200', -height=>'850' )->pack; my $fr1=$p->Frame()->place(-anchor=>'nw', -x=>"50", -y=>"150");; my $listbox1=$fr1->Scrolled('Listbox', -scrollbars=>'e', -exportselection => 0 )->pack; my $fr2=$p->Frame()->place(-anchor=>'nw', -x=>"50", -y=>"150"); my $listbox2=$fr1->Scrolled('Listbox', -scrollbars=>'e', -exportselection => 0 )->pack;
Re: Scrolled within a Scrolled
by zentara (Cardinal) on Nov 28, 2008 at 18:48 UTC
    Your code also seems to work for me. Maybe you are looking for a way to have rows or columns of scrolled widgets? In that case you need to put frames into the Scrolled Pane, then fill the frames with Scrolled widgets. Here is an example with the Scrolled Canvas
    #!/usr/bin/perl use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry('400x250'); my $mwf = $mw->Scrolled('Pane', -scrollbars=>'osoe', -sticky=>'nwse', )->pack(-expand=>1, -fill=>'both'); my $f1 = $mwf->Frame()->pack(); my $f2 = $mwf->Frame()->pack(); my %canv; for (0..4){ $canv{$_}{'obj'} = $f1->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left' ,-padx=>10,-pady=>10); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (5..9){ $canv{$_}{'obj'} = $f2->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } MainLoop();

    I'm not really a human, but I play one on earth Remember How Lucky You Are