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

Fellow monks,

I've got one that is stumping me here.

I wrote a program for an advanced perl class I took that is a regular expressions trainer. So far so good...

I have had a need to use it for a rather long bit of text that I needed to write a regex for and wasn't having any luck with the write-test-write approach in my editor as the resulting text was too long and I couldn't scroll to see it all.

I want to add a scroll bar at this point:

my $restxt=$top->Label(width=>WIDTH, -textvariable=>\$match_results, -bg=>'white', -relief=>'groove', -font=>14, -height=>10, -justify=>'left', )->pack(-side=>'top');

but I'm unclear on how this can be done. I tried to change this to a listbox but that failed spectacularly.

Can anyone point me in a direction on this one?

Thanks!

Some people fall from grace. I prefer a running start...

Replies are listed 'Best First'.
Re: Adding scroll bar in Tk label widget
by rbc (Curate) on Jun 02, 2002 at 05:41 UTC
    If I understand what you are trying to do, you should try using an Entry widget like so ...
    my $restxt=$top->Entry (width=>WIDTH, -textvariable=>\$match_results, -bg=>'white', -relief=>'groove', -font=>14, -height=>10, -justify=>'left', )->pack(-side=>'top');
      Unfortunately that doesn't work as I want to have the multiple line option for when the user is doing an

      m/(something)(something)/

      and it prints out the matches for $1, $2, etc...

      My thought was to just write a function to pop in a \n when the string length returned is over 80 characters. To me this seems like a quick but bad kludge to the problem.

      Is there something in Tk that would allow multiple lines AND a scroll bar?

      Some people fall from grace. I prefer a running start...

        Ah I see ... try something like this then ...
        my $t = $top->Scrolled('Text',"-relief" => "raised", "-bd" => "2", "-setgrid" => "true")->pack();
        This is taken from text_demo which is a script that
        should of been installed when you installed Tk. Tk has lots
        cool demos that pretty much answer most questions.
Re: Adding scroll bar in Tk label widget
by svad (Pilgrim) on Jun 02, 2002 at 13:31 UTC
    may be
    $top->Scrolled('Entry',-scrollbars=>'osoe', # your previously described options go here )->pack(..._
    is what you needed?
    (sorry, can't check the code right now)
Re: Adding scroll bar in Tk label widget
by jepri (Parson) on Jun 03, 2002 at 01:40 UTC
    Create a scrolled frame (or whatever it's called in Tk) and then add your label widget to it.

    Be aware that you are using label for the wrong thing - something like the text widget is much more appropriate for big chunks of multi-line text.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.