Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Perl::Tk--Center line in Text Widget

by vlsimpson (Beadle)
on Dec 18, 2009 at 18:58 UTC ( [id://813417]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://813417]
Approved by planetscape
Front-paged by biohisham
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-23 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found