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

Can I get a hint on centering a line in a Tk::Text widget please.

I'm using $text->see("index") to move to a line in a file, but if it's only a couple of lines invisible it moves up to bottom of window. I'd like to have the line centered in the window (for context purposes).

I've 'Super Search'ed and 'Googled'(TM) my ass off I don't have anything left to sit on ;)

Thanks

Replies are listed 'Best First'.
Re: Perl::Tk--Center line in Text Widget
by Kirsle (Pilgrim) on Dec 18, 2009 at 23:24 UTC

    If you have, say, 100 lines in the text file and only 10 lines are visible at any time in the text widget, and you want line 50 to be shown in the center of the widget... $text->see(50) will scroll it so that line 50 is at the bottom of the text box, but if you did instead $text->see(50 + 5) then it would show line 55 at the bottom of the text box, and line 45 at the top - 50 being approximately right in the center.

    Then to guarantee it will be in the center even if the text widget needed to scroll up to see it, you could first call $text->see(45) and then $text->see(55).

      Excellent, that looks like it'll do it. I'll give it a whirl in the morning (well, my later morning).

      Thanks.