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

Hi all, I'd like to align a scollbar to the right and not to the left (the default). My code:
use strict; my $tally_scroll = $frame11 -> Scrolled("Listbox", -scrollbars => 'osoe', -width => 45, -height => 48, -font => '7x13') -> pack();
In this example, when the length of text exceeds the width of the listbox, the scrollbar always aligns to the left. Can I change this so it goes to the right? Thanks in advance, Stacy.

Replies are listed 'Best First'.
Re: perl/Tk scrollbar aligning
by kevin_i_orourke (Friar) on Nov 30, 2001 at 19:14 UTC

    I'm probably just being thick here but what do you mean by aligning the scrollbar?

    Do you want to change the position of the scrollbar in relation to the listbox? In that case change the specification in -scrollbars => 'osoe', for example 'onow' will put scrollbars on the top and left ('north' and 'west') sides of the listbox.

    Or did you mean that you want the initial position of the 'slider' (the bit that you can slide around that represent the current view) to be set to the right of your listbox? You might be able to do this by $listbox->xview("moveto,1"), or something similar, I don't have time to test this just now. Have a look at the Tk::Scrollbar perldoc.

    Hope that helps.

    Kevin O'Rourke

      I'm after the second option. However, since I've got a Scrolled widget, accessing the scrollbar might have to be done via the Subwidget method: I can change the colour of the scroll bar:
      $tally_scroll -> Subwidget("xscrollbar") -> configure(-bg => 'blue';
      but how to get the slider move to the right? Dunno yet.
        $tally_scroll->xview(3); will move your list _and_ scrollbar (Don't know if you can move only one) 3 letters to the right.
      I think you meant
      $listbox->yview(3);
      for scrolling down the list, xview() would move it left and it accepts only a integer (btw, it starts with 0 of course)
      -- package Lizard::King; sub can { do { 'anything'} };

        No, I meant $tally_scroll->Subwidget("scrolled")->xview(moveto => 1), to scroll the listbox as far right as possible

        perldoc Tk::Listbox:

        *$listbox*->xview(moveto => *fraction*) Adjusts the view in the window so that *fraction* of the total width of the listbox text is off-screen to the left. *fraction* must be a fraction between 0 and 1.

        Kevin O'Rourke

Re: perl/Tk scrollbar aligning
by TomK32 (Monk) on Nov 30, 2001 at 17:05 UTC
    Not sure if it works, no time to test but replace
    pack();
    with
    pack(-side=> 'right');
    update: kevin_i_orourke found the real solution. Ignore my post, but don't steal it!
    -- package Lizard::King; sub can { do { 'anything'} };