in reply to Looking for a standalone separator for Perl/Tk

Just use a simple black (or desired color) frame.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1185809 use strict; use warnings; use Tk; my $mw = MainWindow->new; $mw->Label( -text => 'top part', -height => 5, )->pack; $mw->Frame( -height => 2, -bg => 'black', )->pack( -fill => 'x' ); $mw->Label( -text => 'bottom part', -height => 5, )->pack( -side => 'bottom'); $mw->Frame( -height => 2, -bg => 'black', )->pack( -side => 'bottom', -fill => 'x' ); $mw->Label( -text => 'left part', -height => 5, -padx => 25, )->pack( -side => 'left'); $mw->Frame( -width => 2, -bg => 'black', )->pack( -side => 'left', -fill => 'y' ); $mw->Label( -text => 'right part', -height => 5, -padx => 25, )->pack( -side => 'left'); MainLoop;

Replies are listed 'Best First'.
Re^2: Looking for a standalone separator for Perl/Tk
by kbrannen (Beadle) on Mar 24, 2017 at 18:59 UTC
    Thanks! It's good to know I was on a reasonable path.

    I just wished there was something simpler like:
    use Tk::Separator; $mw->Separator(-orient => 'horizonal')->pack(); # -or- $mw->Separator(-orient => 'vertical')->pack();
    and all of the little details would automatically be taken care of. :) I suppose I could look at writing such a thing. Hmm, maybe I could steal some code from the Menubar or PanedWindow widgets since they have something like that already and make it its own widget.

      Like this ?

      #!/usr/bin/perl # http://perlmonks.org/?node_id=1185809 use strict; use warnings; use Tk; sub Tk::Separator { my ($self, %rest ) = @_; my $direction = delete $rest{'-orient'} // 'horizontal'; $self->Frame( %{ {%rest, -bg => 'black', $direction eq 'vertical' ? '-width' : '-height' => 2 } } ); } my $mw = MainWindow->new; $mw->Label( -text => 'top part', -height => 5, )->pack; $mw->Separator()->pack( -fill => 'x' ); $mw->Label( -text => 'bottom part', -height => 5, )->pack( -side => 'bottom'); $mw->Separator()->pack( -side => 'bottom', -fill => 'x' ); $mw->Label( -text => 'left part', -height => 5, -padx => 25, )->pack( -side => 'left'); $mw->Separator( -orient => 'vertical')->pack( -side => 'left', -fill = +> 'y' ); $mw->Label( -text => 'middle part', -height => 5, -padx => 25, )->pack( -side => 'left'); $mw->Separator( -orient => 'vertical')->pack( -side => 'left', -fill = +> 'y' ); $mw->Label( -text => 'right part', -height => 5, -padx => 25, )->pack( -side => 'left'); MainLoop;
        I'd created a make_separator() to help myself, but I like what you've done better. It feels more Perl/Tk'ish. :) Thanks for the help and the lesson!

        Maybe that will help others who search for this.