wfsp has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk::Text widgets and bulleted lists
by zentara (Cardinal) on Dec 28, 2004 at 11:14 UTC |