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

How to create a scrollbar for multiple objects in TK

by juo (Curate)
on Nov 11, 2004 at 04:12 UTC ( [id://406910]=perlquestion: print w/replies, xml ) Need Help??

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

I have been using a long time Perl with TK and it has been working fine and have been able to do everything I need besides one thing I have never been able to make work is to link a scrollbar to different GUI objects so that I can make a GUI which has more objects then can fit in the screen and that I can use a scrollbar to show them. Does anybody know if this is possible at all in Tk. I put a small example below to show what I mean, what if I have 40 buttons and I want to have them all in the GUI.

Pieter

#!c:/perl/bin/perl use Tk; $mw = MainWindow->new(); $mw->geometry('+0+0'); $mw->title( "Many buttons" ); ## Create Frame of elements my $frame= $mw->Frame( -relief => 'groove', -bd => 1, -height => 5); $frame->pack( -side => 'left',-pady => 1, -fill => 'x'); my $num_of_buttons=10; #my num_of_buttons=40; while ($num_of_buttons > 0) { ## Create Button of elements my $button = $frame->Button( -font => 'system', -text => "test", -activebackground => 'cyan', -width => 34, -state => "active", -relief => "raised", ); $button->pack( -side => 'top', -fill => 'x' ); $num_of_buttons--; } MainLoop();

Replies are listed 'Best First'.
Re: How to create a scrollbar for multiple objects in TK
by pg (Canon) on Nov 11, 2004 at 05:43 UTC

    use scrolled:

    use Tk; use Tk::Pane; $mw = MainWindow->new(); $mw->geometry('+0+0'); $mw->title( "Many buttons" ); ## Create Frame of elements my $frame= $mw->Scrolled('Frame', -relief => 'groove', -bd => 1, -scrollbars=>"se"); $frame->pack(-fill => 'both', -expand => 1); my $num_of_buttons=10; #my num_of_buttons=40; while ($num_of_buttons > 0) { ## Create Button of elements my $button = $frame->Button( -font => 'system', -text => "test", -activebackground => 'cyan', -width => 34, -state => "active", -relief => "raised", ); $button->pack( -side => 'top', -fill => 'x' ); $num_of_buttons--; } MainLoop();

      I have tried this snippet of code but I see no different between this and the original code. No scrollbars are seen anywhere. I believe the scrollbar also need also to be configured before it can be used.

      Vicky

        "I have tried this snippet of code but I see no different between this and the original code. "

        The solution was tested before I post it, as I always do. My testing was done on WinXP with AS Perl 5.8.4.

        "No scrollbars are seen anywhere."

        I saw scrollbars around the main frame (actually not really the main frame, but the frame added on top of it, but visually it looks like the scrollbars are for the main frame.) And when you resize the window, the scrollbars move along.

        "I believe the scrollbar also need also to be configured before it can be used. "

        I did configured scrollbars with Scrolled.

        I came up with the same thing, but mine didn't work at all in practice either, though it should.

        I'm using perl 5.8.0 on i386 linux

        Maybe Scrolled has a platform dependant bug, and Tk::Scrollbar has to be used instead?


        --
        Snazzy tagline here
Re: How to create a scrollbar for multiple objects in TK
by zentara (Archbishop) on Nov 11, 2004 at 16:43 UTC
    pg's code worked for me, but maybe you need to explicitly created a scrolled Pane. He created a Scrolled Frame, which seem to automatically work on latest version of Perl and Tk on linux, but maybe on Windows or other Tk versions, its a problem?
    use Tk; use Tk::Pane; .....snip.... ## Create Frame of elements my $frame= $mw->Scrolled('Pane', -relief => 'groove', -bd => 1, -scrollbars=>"se"); $frame->pack(-fill => 'both', -expand => 1);

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found