The problem with this approach

my $f = $LB->tagCget("A$this", -font); printf "Mark: %d,%s\n",$this, $f; if (${$f} =~ /normal/i) {

When there is no font, then $f is not a reference, so program should first check if there is a reference

But the real problem, why modify tag options when should be adding/removing tags? markAccount should toggle a 'markAccount' tag for ALine

update:

On every double click, toggle bolded for A1

#!/usr/bin/perl -- use strict; use warnings; use Tk; use Data::Dump qw/ dd /; my $mw = Tk::MainWindow->new; $mw->geometry('400x300'); my $tw = $mw->Text(-wrap=>'word')->pack(qw/ -expand 1 -fill both /); $tw->insert( 'end', q{"There must be some kind of way out of here," Said the joker to +the thief.}, 'A1', ); $tw->tag( 'bind', 'A1', '<Double-1>', \&AnDouble ); $tw->tagConfigure( 'bolded', -font => 'courier 18 bold' ); MainLoop; sub AnDouble { #~ my( $tw ) = @_; #~ my $tw = $Tk::widget; my $tw = $Tk::event->W; my $mouseIndex = $tw->index( sprintf '@%s,%s',$Tk::event->x , $Tk: +:event->y ) ; my @tags = $tw->tagNames( $tw->index('A1.first') ); dd( [ $mouseIndex => @tags ], map { [ $_ => $tw->tagRanges($_) ] } + $tw->tagNames ); if( grep /bolded/, @tags ){ $tw->tagRemove('bolded', $tw->tagRanges('A1') ); } else { $tw->tagAdd('bolded', 'A1.first','A1.last' ); } } __END__ $ perl tk-text-toggle-tagadd.pl ([1.9, "A1"], ["sel"], ["A1", "1.0", 1.74], ["bolded"]) ( [1.4, "A1", "bolded"], ["sel", 1.1, 1.11], ["A1", "1.0", 1.74], ["bolded", "1.0", 1.74], )

In reply to Re: How to extract, delete TK tags' option/value (Tk ROText indices index tagAdd tagRemove) by Anonymous Monk
in thread How to extract, delete TK tags' option/value by jsteng

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.