The script below is a crude attempt to adds bullets to selected lines in a Text widget.

Is there was a way to make the bullets read only? If the bullets need to be removed the format (tags) should be removed (sub not shown) not by just deleting the bullets.

What is the best way to do this?

#!/bin/perl5 use strict; use warnings; use Tk; my $mw = MainWindow->new(-title => 'bullets'); my $t = $mw->Text->pack; { local $/ = undef; $t->insert('1.0', <DATA>); } $t->tagConfigure( 'bullets', -lmargin1 => '30', -lmargin2 => '61', ); $mw->Button(-text => 'bullet', -command => \&bullets)->pack; MainLoop; sub bullets{ unless ($t->tagRanges('sel')){ print "Can't apply bullets - no text selected\n"; return; } my $first_index = $t->index('sel.first'); my $last_index = $t->index('sel.last'); my $first_line = line_number($first_index); my $last_line = line_number($last_index); $t->unselectAll; for my $line ($first_line..$last_line){ $t->GotoLineNumber($line); $t->insert("$line.0", "* "); } $t->tagAdd('bullets', "$first_index linestart", "$last_index lineen +d"); return; } sub line_number{ my $index = shift; my ($line) = $index =~ /^(\d+)\./; return $line; } __DATA__ Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.

In reply to Tk::Text widgets and bulleted lists by wfsp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.