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

I have issues with this function. The documentation says:
$text->see(index) Adjusts the view in the window so that the character given by index is completely visible. If index is already visible then the command does nothing. If index is a short distance out of view, the command adjusts the view just enough to make index visible at the edge of the window. If index is far out of view, then the command centers index in the window.
To me this means if the "index" is slightly to the top of the visible screen it will move the "index" position to the top edge of the widget window. If the "index" is slightlly off the screen to the bottom of the widget window it will position the "index" at the bottom edge of the window.

However when I use this function it seems to want a value in the form of x.x (line.character). I give it this value and it runs fine but when this value gets to be 2.0 the scroll fucntion jumps to the very last line (in this case 950).

Why is this?

Here is the subroutine in question:

sub line_num { my $total_lines = shift; my $line_number = ($t->index('insert')); print $line_number,"\n"; $linenumbers->delete("1.0", "end"); for (0..$total_lines) { $linenumbers->insert('end', join "\n", map {sprintf "%4d", $_ } +$_); } #$linenumbers->yviewMoveto($line_number/$total_lines); #$linenumbers->yview(-pickplace, $line_number); $linenumbers->see($line_number); }

Replies are listed 'Best First'.
Re: Valid values of Tk::Text see() function.
by JamesNC (Chaplain) on Jul 30, 2004 at 03:08 UTC
    Without seeing the rest of your code and not really sure what value the widget ( $t->index('insert') ) is actually returning, you said '2.0'... Since I am not sure what widget you are using... I would maybe try qq/ $t->index('insert')/ or $t->index('insert').""... since perl may be trying to cast the index into a number instead of leaving it as a string The following works for me on AS 5.8.3 build 809 and Tk 804.021:
    use Tk; use strict; my $mw = tkinit; $mw->geometry('100x100'); my $linenumbers = $mw->Text()->pack(-fill, 'both', -expand, 1); &line_num(30); MainLoop; sub line_num { my $total_lines = shift; #my $line_number = qq($t->index('insert')); #? my $line_number = '21.0'; print $line_number,"\n"; $linenumbers->delete("0.1", "end"); for (0..$total_lines) { $linenumbers->insert('end', join "\n", map {sprintf "%4d\n", $_ +} $_); } #$linenumbers->yviewMoveto($line_number/$total_lines); #$linenumbers->yview(-pickplace, $line_number); $linenumbers->see($line_number); }

    JamesNC
      I don't want to be picky, but seeing this section of your code:
      #my $line_number = qq($t->index('insert')); #? my $line_number = '21.0'; print $line_number,"\n";
      I wonder whether you're really doing what the OP wanted to. After all you're just hard coding the line number...
        I don't know what widget $t is? It is definitely not the same widget he is using see() with and he is using the insertion point index of that widget. So, just working the problem backwards to that line should convince him that the problem is not in the see() function, but in the arguements he gave to it. Plug in '2.0' and it still works fine.