in reply to Re: how can i create a scrollbar in the main window using perl tk
in thread how can i create a scrollbar in the main window using perl tk

I dont want to associate any widget(listbox) to the scrollbar. I just want to have a scrollbar that will appear in the main window when it is populated, e.g with other frames (containing widgets like table, entry) that appears on the main window after pressing some buttons on the main window and disappears, pressing those buttons again. Any help !! Thanks in Advance.
  • Comment on Re^2: how can i create a scrollbar in the main window using perl tk

Replies are listed 'Best First'.
Re^3: how can i create a scrollbar in the main window using perl tk
by imrags (Monk) on Dec 18, 2008 at 07:48 UTC
    Then you can try something like this:
    $mw->Scrollbar()->pack(-side => 'right', -fill => 'y');
    And then you can associate it with any widget. Check out: PerlTK
    Njoi
    Raghu
      Thanks!! Can i associate frames with the scrollbar? If yes then How? Also there are multiple frames, how can I associate the scrollbar with all of them?
        If you want to control the bindings of your scrollbars manually, it is a PITA full of details. Here is a decent example

        However, if you don't need the same scrollbar linking multiple widgets, you usually just use a scrolled Pane, and add frames to the scrolled Pane, then addwhatever you want to the Frames. Like:

        #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; my $mw = tkinit; my $spane = $mw->Scrolled('Pane', -scrollbars => 'osoe', -bg => 'blue', )->pack(-expand => 1, -fill => 'both'); # create 2 frames side by side in the pane, and fill with more frames my $lframe = $spane->Frame(-bg=>'red')->pack(-side=>'left',-padx=>3); my $rframe = $spane->Frame(-bg=>'red')->pack(-side=>'right',-padx=>3); my %frames; for(1..100){ $frames{$_}{'frame'} = $lframe->Frame()->pack(-pady => 5 ); $frames{$_}{'label'} = $frames{$_}{'frame'}->Label(-text=>'Frame '.$ +_)->pack; my $num = $_; $frames{$_}{'button'} = $frames{$_}{'frame'}->Button( -text=>'Button '.$_, -command => sub{print "$num pressed\n"}, )->pack; } for(101..200){ $frames{$_}{'frame'} = $rframe->Frame()->pack(-pady => 5 ); $frames{$_}{'label'} = $frames{$_}{'frame'}->Label(-text=>'Frame '.$ +_)->pack; my $num = $_; $frames{$_}{'button'} = $frames{$_}{'frame'}->Button( -text=>'Button '.$_, -command => sub{print "$num pressed\n"}, )->pack; } MainLoop;

        I'm not really a human, but I play one on earth Remember How Lucky You Are
        Check the same documentation.
        A frame is just another widget...
        You can link different type of widgets to scrolled.
        So that should not be a problem for you.
        If it doesn't work, You can always go back to Scrolled method for doing the same.
        Raghu