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

I'm using the Tk::Text module, and I'm stumbling through the docs trying to figure out how to use the "mark' method.

All I want to do is keep track of certain elemtnts I'm inserting into my text, and at some point insert more text below the appropriate mark.
I'm using the following code as my trial, and I'm trying to insert "Foo" below Second

#!usr/bin/perl use warnings; use strict; use Tk; use Tk::Text; use vars qw($text); &init_ui; $text->insert('0.0', "First\n"); $text->insert('end', "Second\n"); $text->insert('end', "Third\n"); $text->markSet("Foo"); ## Not sure about this MainLoop; sub init_ui { my $mw = MainWindow->new( -title => 'Mark in Text ??'); $mw->resizable(0,0); $text = $mw->Scrolled(qw/Text -relief sunken -borderwidth 2 -height 12 -width 35 -wrap word -scrollbars e/ )->pack(-side => 'top'); }
Can anyone help?

Replies are listed 'Best First'.
Re: Using mark in Tk::Text
by traveler (Parson) on Apr 14, 2003 at 16:31 UTC
    This should fix it. You need to tell the mark where it is to be set. Here is the changed part.
    $text->insert('0.0', "First\n"); $text->insert('end', "Second\n"); # $text->markSet('Foo', '3.0'); #make mark at start of line 3 $text->markSet('Foo', 'end-1 chars'); #make mark after last inserted t +ext $text->markGravity('Foo','left'); $text->insert('end', "Third\n"); $text->insert('Foo', "-inserted-\n"); MainLoop;
    HTH, --traveler
      Thanks traveler!
      Now if I understand "marks", I can now refer back to the word 'Foo', and insert text below 'second' at any time correct?
        Correct.

        --traveler