I've hit a situation where using the "-font" option in defining a Tk Text widget leads to a Segmentation Fault. The version below works correctly unless you switch the comment-out from line 22 to line 20. Does anyone know why?

#!/usr/bin/perl -w use strict; use Tk; use Tk::NoteBook; my $MW = MainWindow->new(); my $note = $MW->Label(-font=>'courier-12',-text=> "F1-4 presents/withdraws the notebook windows.")->pack(); my (@VW, @NB, %pg, %txt); foreach (0..3) { my $title = eval("$_+1"); $VW[$_] = $MW->Toplevel(-title=>"$title"); $VW[$_]->state('wit +hdrawn'); $NB[$_] = $VW[$_]->NoteBook()->pack(); foreach my $L ("A","B","C","D") { my $name = "$L-$title"; $pg{$name} = $NB[$_]->add($name,-label=>'empty'); } } foreach (keys %pg) {$txt{$_} = $pg{$_}->Text()->pack()} # this version causes a seg fault: #foreach (keys %pg) {$txt{$_} = $pg{$_}->Text(-font=>"courier-12")->pa +ck()} $MW->bind('all',"<Key-F1>"=>sub{toggle(0)}); $MW->bind('all',"<Key-F2>"=>sub{toggle(1)}); $MW->bind('all',"<Key-F3>"=>sub{toggle(2)}); $MW->bind('all',"<Key-F4>"=>sub{toggle(3)}); MainLoop;################## sub toggle { my $n = "@_"; my $state = $VW[$n]->state(); my $newstate = ($state eq 'withdrawn') ? 'normal' : 'withdrawn +'; $VW[$n]->state("$newstate"); }

In reply to Tk Text -font=>segfault by halfcountplus

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.