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

Hi,

in perl tk, the options '-padx' places padding on the left and right side of the widget. The option '-pady' places padding on the top and bottom side of the widget.

But what do I have to do, if I just want to have e.g. a padding on the left side of the widget and NOT on the right side?

Thank you for your help
Dirk

Replies are listed 'Best First'.
Re: Perl/Tk padding only on one side
by keszler (Priest) on Nov 16, 2009 at 10:17 UTC
    If you're using the grid geometry manager you can insert an empty column left of the widget and specify its minimum width. If there are widgets above or below that need to be in that space just colspan them.

    For the pack geometry manager you can insert an empty, border-less frame sized appropriately.

    With the place geometry manager you specify x and y positions; choose appropriately.

    The form geometry manager has pad options for left/right/top/bottom.

Re: Perl/Tk padding only on one side
by biohisham (Priest) on Nov 16, 2009 at 09:46 UTC
    You haven't specified the type of the widget, there are some widget specific options, look at Tk::Text this widget has options (tags) like:

    • "-justify=>*justify*" with options (left, right, center).
    • "-lmargine1=>*pixels*".
    • "-lmargine2=>*pixels*".
    • "-rmargine=>*pixels*"

    This might only address your inquiry, in part, with regard to a limited array of Widgets in Tk, because, many Tk widgets have their specific options in addition to the shared options....

    Update:since the OP later explained that the widget is a frame these options and tags are specific to text widgets and not frames.


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
      The type of my widget is a frame. I tried "-lmargine1",but this option is unfortunately not working with a frame.
Re: Perl/Tk padding only on one side
by zentara (Cardinal) on Nov 16, 2009 at 13:07 UTC
    ...you also might want to try the -anchor option.... a simple example of what you want would be helpful......but look at this
    #!/usr/bin/perl use Tk; use strict; use warnings; my $mw = MainWindow->new( -bg => 'beige', ); my $l = $mw->Frame( -width => 111, -height => 333, -relief => "raised", -borderwidth => 2, -bg => '#EEE000', )->pack( -fill => 'x', -side => 'left', -anchor => 'n', ); my $r = $mw->Frame( -width => 111, -height => 333, -relief => "raised", -borderwidth => 2, -bg => '#F0F000', )->pack( -fill => 'both', -side => 'left', -anchor => 'n', ); my $r2 = $mw->Frame( -width => 111, -height => 333, -relief => "raised", -borderwidth => 2, -bg => '#F0F000', )->pack( -fill => 'both', -side => 'left', -anchor => 'n', ); for ( qw[Name: Version: Description: Date: ] ){ $l->Label( -text => $_, -justify => 'left', -anchor => 'w', )->pack( #-anchor => 'e', # if you don't fill -fill => 'x', ); $r->Label( -text => $_, # -justify => 'right', -anchor => 'e', )->pack( -anchor => 'e', # if you don't fill #-fill => 'x', ); $r2->Label( -text => $_, -justify => 'right', # -anchor => 'e', )->pack( #-anchor => 'e', # if you don't fill #-fill => 'x', ); } #$top->Label(-text => "Enter the scroll frame")->pack; MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
Re: Perl/Tk padding only on one side
by stefbv (Priest) on Nov 16, 2009 at 13:48 UTC
    Use: -padleft or -padright
      .... just checking...i don't see a padleft or padright option in my linux Tk..... where did you see it? win32? ......as usual alignment is all explained in perldoc Tk::pack and perldoc Tk::grid

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku
        The form geometry manager has this options both on GNU/Linux and win32. :)