I have configured a Help button via Tk and find that the Text of my Help doesn't redisplay when I click the button a second time. I get the proper Window title but only a small blank little screen on the second invocation and an error message indicating, among other things

Tk::Error: font "bold14c" already exists at C:/Perl/site/lib/Tk/Submet +hods.pm line 19.

The message is referring to font(s) I created via:

$TOP->fontCreate(qw/bold14c -family courier -size 14 -weight b +old/); $TOP->fontCreate(qw/bold18h -family helvetica -size 18 -weight b +old/);

I'd like to embed a test for their existence (for those second-time-through-invocations) with something like

unless ( grep { $_->actual('-Name') =~ /bold14c/ } $TOP->fontNames ) { $TOP->fontCreate(qw/bold14c -family courier -size 14 -weight b +old/); $TOP->fontCreate(qw/bold18h -family helvetica -size 18 -weight b +old/); }

(assumes finding one font means don't need to check for the other font) but this doesn't seem to be the right way to extract the name of the font out of the object(s) that the fontNames method is kicking out for me. So the question is: how to know what the names of the fonts are since fontNames only kicks out objects?

Something that redisplays the Help screen with proper fonts is to do:

$TOP->fontDelete('bold18h', 'bold14c');

at the bottom of my sub that displays the Help (after it has succeeded) and just let the Help button do another fontCreate when reinvoked, but create/delete/create/delete/etc seems messy.


In reply to Tk fontCreate, fontNames errors (and fontDelete seems messy) by ff

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.