Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Tk::Scrollbar don't know how to use it properly

by exilepanda (Pilgrim)
on Sep 11, 2014 at 05:01 UTC ( #1100234=perlquestion: print w/replies, xml ) Need Help??

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

Can somebody kindly tell me what's wrong with this code ? The scroll bar won't stick with the frame but just like another widget placing inside the frame.
use Tk; use Tk::Scrollbar; my $mw = new MainWindow; my $f = $mw -> Frame() -> pack; $f->Button ( -text=> $_ )->pack for ( 1..50 ) ; $f->Scrollbar () -> pack ; MainLoop;

Replies are listed 'Best First'.
Re: Tk::Scrollbar don't know how to use it properly
by zentara (Archbishop) on Sep 11, 2014 at 09:58 UTC
    When you manually make Scrollbars, you must define what they do. Use a Tk::Scrolled widget if you want automatic scrolling. Sometimes, an short example is worth 10,000 words. See Re: I seek illumination and knowledge or
    #!/usr/bin/perl ########## use Tk; use strict; my $mw=tkinit; my $c=$mw->Scrolled('Canvas', -width=>400, -height=>400, -bg=>'red', -scrollregion=>[0,0,1000,1000], -scrollbars=>'se')->pack(-expand=>1, -fill=>'both'); $c->create('rect',&n) for (0..40); my $id = $mw->repeat(100,sub{ $c->xviewScroll(1,'units'); $c->yviewScroll(1,'units'); }); $mw->after(10000, sub{$id->cancel}); MainLoop; sub n { my ($x1,$y1) = ( rand(1000), rand(1000) ); my ($x,$y) = ($x1/2,$y1/2); return ($x,$y,$x1,$y1); }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Tk::Scrollbar don't know how to use it properly ( Scrolled )
by Anonymous Monk on Sep 11, 2014 at 06:32 UTC
      Thanks for reply, actually i have another piece of code that uses Tk::Scrolled, and it works perfectly oků but i just like to give a try on Scrollbar, as its interf ace looks like i can "attach" a scroll bar after a widget is created, in contrast that a scroll widget wraps the real widget that i want to operate. Though, i am still learning how to read the GUI documentation at the same time.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-02-17 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (71 votes). Check out past polls.

    Notices?