Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Tk Text -font=>segfault
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[d_] = $MW->Toplevel(-title=>"$title"); $VW[ _]->state
('withdrawn');
$NB[d_] = $VW[K_]->NoteBook()->pack();
foreach my $L ("A", B   C   D ) { my $name = "$L-$title";
MainLoop;###$pg{#name} = $NB[ _]->add($name,-labe =>'empty');
}
}
foreach (keys %pg) {$txt{$_} = $pg{a_}->Text()->pack()}
#       this version causes a seg fault:
#foreach (keys %pg) {$txt{$_} = $pg{$_}->Text(-font=>
"courier-12")->pack()}
$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");
}

Report this thread to moderator Post Follow-up to this message
Old Post
MK
03-28-08 12:21 AM


Re: Tk Text -font=>segfault
perhaps because i am fooling with vim character encodings the code in the
post is a bit screwed up. Sorry! try:

#!/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
('withdrawn');
$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")->pack
()}
$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");
}

this is also on PerlMonks:
http://perlmonks.org/index.pl?node_id=676855

it may be a glitch in 5.8.8.  If you use 5.10 on linux please test it for
me.

Report this thread to moderator Post Follow-up to this message
Old Post
MK
03-28-08 12:21 AM


Re: Tk Text -font=>segfault
On Mar 27, 5:22 pm, MK <halfcountp...@intergate.com> wrote:
> 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?



> foreach (keys %pg) {$txt{$_} = $pg{a_}->Text()->pack()}
> #       this version causes a seg fault:
> #foreach (keys %pg) {$txt{$_} = $pg{$_}->Text(-font=>
>         "courier-12")->pack()}

I try to avoid using $_ as a loop variable.  If something
changes $_ implicitly inside the loop it will corrupt the
hash.  Note that there is only one $_.

Why not use something more straightforward:

while (($key, $w) = each %pg) {
$txt{$key} = $w->Text(-font=>"courier-12")->pack();
}


Report this thread to moderator Post Follow-up to this message
Old Post
smallpond
03-28-08 12:21 AM


Re: Tk Text -font=>segfault
MK wrote:
> perhaps because i am fooling with vim character encodings the code in the
> post is a bit screwed up. Sorry! try:
te");
> }
>
> this is also on PerlMonks:
> http://perlmonks.org/index.pl?node_id=676855
>
> it may be a glitch in 5.8.8.  If you use 5.10 on linux please test it for
> me.

Hi,
can't reproduce your issue with 5.8.8 , latest perl/Tk.
did you try -font => [courier => 12] or other font descriptions as well?

Btw: Negative values for fontsizes are Pixels not Points.

Christoph

Report this thread to moderator Post Follow-up to this message
Old Post
Lamprecht
03-28-08 12:21 AM


Re: Tk Text -font=>segfault
On Thu, 27 Mar 2008 17:49:18 -0500, MK <halfcountplus@intergate.com>
wrote:

>perhaps because i am fooling with vim character encodings the code in the
>post is a bit screwed up. Sorry! try:

Your script works fine for me on linux, with Perl 5.8.8

In addition to what others have said, I have found from previous
problems like this, that it is best to declare your fonts first,
as shown below.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = new MainWindow;

$mw->fontCreate('big',
-family=>'arial',
-weight=>'bold',
-size=>int(-18*18/14));

$mw->fontCreate('medium',
-family=>'courier',
-weight=>'bold',
-size=>int(-14*14/10));

my $entry = $mw->Entry(-font =>'big',-text=>'Big')->pack();
my $entry1 = $mw->Entry(-font =>'medium',-text=>'medium')->pack();

MainLoop;
__END__


zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Report this thread to moderator Post Follow-up to this message
Old Post
zentara
03-29-08 12:15 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:58 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.