Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Perl Tk compound formatting

by CColin (Scribe)
on Jun 06, 2013 at 23:09 UTC ( [id://1037522]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Tk compound formatting
in thread Perl Tk compound formatting

Question: Sorry to bother you again, but how to add a scrollbar to this since the number of buttons may disappear off the page. I see that you have aded a mainwindow and a child window (somehow). I have tried the following code to create a scrollbar, but it only appears in the main window where there are no buttons displayed, rather than the child window:
my $scrollbar = $mw->Scrollbar( ); my $lb = $mw->Listbox(-yscrollcommand => ['set' => $scrollbar]); #Configure the Scrollbar to talk to the Listbox widget $scrollbar->configure(-command => ['yview' => $lb]); #Pack the Scrollbar first so that it doesn't disappear when we resize $scrollbar->pack(-side => 'right', -fill => 'y'); $lb->pack(-side => 'left', -fill => 'both');

How to get this scrollbar to appear alongside the buttons that are listed in the child window?

Replies are listed 'Best First'.
Re^3: Perl Tk compound formatting
by Anonymous Monk on Jun 06, 2013 at 23:21 UTC
    scrollbars are kind of PITA to setup, which is why there is  $parent->Scrolled( 'widgetname', ... widgetoptions ... )->pack see Tk::Scrolled
Re^3: Perl Tk compound formatting
by thundergnat (Deacon) on Jun 07, 2013 at 12:32 UTC

    You don't want to (can't actually) scroll the main window directly. You need to insert a scrolled Frame or Pane into the toplevel (main window) then pack your widgets inside that.

    use strict; use warnings; use Tk; use Tk::Pane; my %w; $w{mw} = MainWindow->new; $w{mw}->geometry('220x350'); $w{bframe} = $w{mw}->Scrolled( 'Frame', -scrollbars => 'oe' )->pack( -expand => 1, -fill => 'both' ); for (qw/ this that a_longer_name X cheese verb witty_retort superstiti +on A..Z whatever/){ my $bttn = $w{bframe}->Button( -text => "$_", -font => 'times 19', -justify => 'left', -compound => 'right', -bitmap => ('error','info','question','warning')[rand 4], -anchor => 'e', -padx => 4, )->pack; push @{$w{buttons}}, $bttn; } $w{mw}->update; { my $width = 0; for (@{$w{buttons}}) { $width = $_->width if $_->width > $width; } for (@{$w{buttons}}) { $_->configure(-width => $width); } } MainLoop;
      Great, works well again. The geometry introduced has squashed the buttons but that reconfigures easily. Thanks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-16 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found