Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Scrollbars in Perl::Tk

by Anonymous Monk
on Jan 15, 2004 at 00:18 UTC ( #321429=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks and fellow enlightened beings,

I'm trying to make a frame I have in Perl::Tk that is populated with many widgets into a scrollable frame if the frame gets too long. I'm doing something wrong although I'm not sure what. Help appreciated?

Thanks
Dean

if (! Exists($h_int_frame)) { $h_int_frame = $hframe->Frame->pack; } else { $h_int_frame -> DESTROY; $h_int_frame = $hframe->Frame->pack; } my $scroll_frame = $hframe->Scrolled ('Frame', -scrollbars => 'e')->pa +ck;

Comment on Scrollbars in Perl::Tk
Download Code
Re: Scrollbars in Perl::Tk
by pg (Canon) on Jan 15, 2004 at 03:12 UTC

    You cannot pass Frame widget to Scrolled. Only those widgets that support -xscrollcommand and -yscrollcommand can be passed to Scrolled.

    Unfortunately, at this point, no warning or error message will be given, and your attempt will just be quietly discarded.

      You cannot pass Frame widget to Scrolled.
      I know you can(works for me).
      #!/usr/local/bin/perl -W #tk.scroll.frame.pl use Tk; use strict; use vars qw($top $drop); $top = new MainWindow; $top->Label(-text => "Enter the scroll frame")->pack; $top = $top->Scrolled('Frame', -scrollbars => "osoe",)->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; $top->Label(-text => "Inside the scroll frame")->pack; MainLoop;
      Anonymous Monk isn't showing enough code, but my ESP tells me he's got a logical error (not packing the frame he needs/wants it or not having it as a child of his scrollable frame or something).

      update: screenshot on my Win2K box, perl5.6.1, Tk 800.025.

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        For what it's worth, the example you posted runs without errors here, but yields a window without scrollbars.

        Tk 800.024, Perl 5.8.0, on a gentoo linux install running mostly stable packages.

      Thanks, that appears correct. I'll find some other way around this problem and let you know the result. :-)

      Dean
Re: Scrollbars in Perl::Tk
by zentara (Archbishop) on Jan 15, 2004 at 16:05 UTC
    I don't have an example handy right now, but often the Tk::Pane widget comes in handy when you need to add scrollbars. Just dump a scrolled Pane into the window.
    my $pane = $mw->Scrolled('Pane', Name => 'scroll test', -width => 600, -height => 400, -scrollbars => 'osoe', -sticky => 'ne', ); $pane->pack;
Re: Scrollbars in Perl::Tk
by zentara (Archbishop) on Jan 15, 2004 at 17:58 UTC
    Well here is a script, that shows how to add scrollbars to a frame, using a pane.
    #!/usr/bin/perl use Tk; use Tk::Pane; my $mw = tkinit; my $f = $mw->Frame(-bg=>'black')->pack; my $p = $f->Scrolled('Pane', -scrollbars => 'osoe',)->pack; $p->Label(-text => 'long label long label long label long label long l +abel')->pack; MainLoop;
Re: Scrollbars in Perl::Tk
by elef (Friar) on Jan 13, 2012 at 09:43 UTC
    I bumped into this old thread looking for a way to make my main window scrollable. Both the suggested solutions work for me, but both are incomplete. With the code posted, the frame remains a postage stamp sized rectangle in the middle of the mainwindow when the mainwindow is resized. I added the options (-fill => 'both', -expand => 1) to pack for the frame (and pane) and now things look as they should.
    For some strange reason, Scrolled even shrinks the frame it's added to. If I run PodMaster's code as is, the frame is too small to fit all the text.
    Here's what PodMaster's code generates for me:
    Default view of the window generated after removing the scrollbars from the code: http://dl.dropbox.com/u/16377950/kepek/scrollframe_1.png
    PodMaster's version with what are intended to be optional scrollbars: http://dl.dropbox.com/u/16377950/kepek/scrollframe_2.png - note that both scrollbars are showing up even though they should disappear when the window is this large, and that text is left off both vertically and horizontally.
    After adding (-fill => 'both', -expand => 1): http://dl.dropbox.com/u/16377950/kepek/scrollframe_3.png - horizontal scrollbar disappeared as the window is wide enough to show all text, vertical scrollbar showing up.

      I bumped into this old thread looking for a way to make my main window scrollable.

      Hi

      Please don't bump, zombies are hard to see :)

      You should post a new question in Seekers Of Perl Wisdom and link to this old one

      In the meantime, you could however consider this node for SOPW-ification, your choice :)

      Regarding the code, I see the same images as you, but I'm not sure what behavior you're after or what you consider a problem.

      Consider adding color :)

      #!/usr/bin/perl -- use Tk; use strict; use vars qw($top $drop); $top = tkinit( qw/ -background green /); $top->Label( qw/ -background red /, -text => "Enter the scroll frame" )->pack; $top = $top->Scrolled( 'Frame', qw/ -background pink -scrollbars osoe / )->pack( qw/ -fill both -expand 1 / ); $top->Label( -text => "Inside the scroll frame $_" )->pack for 1 .. 12; MainLoop;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://321429]
Approved by jweed
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-08-31 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls