Tk - text->insert looses the format

M

MoshiachNow

HI,
The same string ($temp) formated with sprintf,is correctly printed to a
file using "print",but looses all it's formating when displayed in the
Tk text->insert:

$temp=sprintf("%-55s %-30s %-10s %-16s %-10s\n", $key, $services{$key},
$state{$status{CurrentState}}, $startup{$value}, $status{ServiceType});

&disp($temp);

sub disp {
my $message=shift;
$txt -> insert('end',$message);

print "$message";
}


Appreciate any ideas.
 
P

Paul Lalli

MoshiachNow said:
HI,
The same string ($temp) formated with sprintf,is correctly printed to a
file using "print",but looses all it's formating when displayed in the
Tk text->insert:

$temp=sprintf("%-55s %-30s %-10s %-16s %-10s\n", $key, $services{$key},
$state{$status{CurrentState}}, $startup{$value}, $status{ServiceType});

&disp($temp);

sub disp {
my $message=shift;
$txt -> insert('end',$message);

print "$message";
}


I can't reproduce the problem with ActiveState build 819, perl v5.8.8.
The following program creates the text box with exactly the formatting
anticipated. Fifty five spaces for the first field, etc. Are you sure
your text box is large enough to show the formatting correctly?

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

my $mw = MainWindow->new();
$mw->geometry('1024x768');
my $txt = $mw->Text(-height=>768, -width=>1024);
$txt->pack();

my $temp=sprintf("%-55s %-30s %-10s %-16s %-10s\n",
"field number 1",
"second field",
"numero tres",
"4th",
"and the final field");

disp($temp);

MainLoop;

sub disp {
my $message=shift;
$txt -> insert('end',$message);
print "$message";
}
__END__
 
M

MoshiachNow

Hi,

The issue was to use the proportional font (courier) instead of Arial
....

:)
 
Z

zentara

The same string ($temp) formated with sprintf,is correctly printed to a
file using "print",but looses all it's formating when displayed in the
Tk text->insert:

$temp=sprintf("%-55s %-30s %-10s %-16s %-10s\n", $key, $services{$key},
$state{$status{CurrentState}}, $startup{$value}, $status{ServiceType});

&disp($temp);

sub disp {
my $message=shift;
$txt -> insert('end',$message);

print "$message";
}


Appreciate any ideas.

Maybe because the text widget is wrapping it, like a terminal does?

Try:

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

my $mw = tkinit;

my $txt = $mw->Scrolled('Text',
-wrap => 'none',
)->pack;

my $temp=sprintf("%-55s %-30s %-10s %-16s %-10s\n", 'abxvdgejhr',
'zcvzxcvzxcv','good', 'yadda yadda', 'gizmo');

&disp($temp);

MainLoop;

sub disp {
my $message=shift;
$txt -> insert('end',$message);

print "$message";
}
__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top