Tk::Checkbutton - text does not line up ...

M

MoshiachNow

HI,

Using a function on Windows,I define a $test variable as following:

$text=sprintf("%-35s %-13s",$_,'(directory)');

Then define the checkbutton:

$button[$i] = $dialog5->Checkbutton(-text => "$text",-variable =>
\($var->{$_}),-relief => 'flat')->pack(@pl);

The text in $text DOES NOT get lined up !

If at the same time I print $text to the black window

print "$text\n";

the text DOES look lined up.

What is wrong ?
Thanks
 
D

Dave

MoshiachNow said:
HI,

Using a function on Windows,I define a $test variable as following:

$text=sprintf("%-35s %-13s",$_,'(directory)');

Then define the checkbutton:

$button[$i] = $dialog5->Checkbutton(-text => "$text",-variable =>
\($var->{$_}),-relief => 'flat')->pack(@pl);

The text in $text DOES NOT get lined up !

If at the same time I print $text to the black window

print "$text\n";

the text DOES look lined up.

What is wrong ?
Thanks

By default the text is 'center' anchored; you probably don't want this so
try setting the -anchor option, e.g. anchor => 'w', as appropriate.
 
C

Ch Lamprecht

By default the text is 'center' anchored; you probably don't want this so
try setting the -anchor option, e.g. anchor => 'w', as appropriate.
In addition you might consider using a fixed-width font to have the second part
of your label aligned vertically as well:

use strict;
use warnings;
use Tk;
my $mw = tkinit();
my @text =
map {sprintf("%-35s %-13s",$_,'(directory)')
} qw(test something_else);
my @buttons =
map {$mw->Checkbutton(-text => $text[$_],
-font=>[courier => 9]
)->pack(-anchor=>'w')
} (0,1);

MainLoop();


Christoph
 
M

MoshiachNow

In addition you might consider using a fixed-width font to have the second part
of your label aligned vertically as well:


Thanks !

This worked like magic !!
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top