Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
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


Long live king Moshiach !
 
Your call to pack() must have certain parameters to get the checkbuttons to line up. I don't know what's in your @pl, but here is generally how to do it:

Code:
use Tk;

my $mw = MainWindow->new;

my %buttons = (
	red     => 1,
	blue    => 0,
	green   => 1,
	yellow  => 1,
	cyan    => 0,
	magenta => 1,
);

foreach my $color (keys %buttons) {
	$mw->Checkbutton (
		-variable   => \$buttons{$color},
		-text       => $color,
		-foreground => $color,
		-onvalue    => 1,
		-offvalue   => 0,
	)->pack (-anchor => 'w');
}

MainLoop;
 
Thanks,

I think my @pl does that more or less:

my(@pl) = qw/-side top -anchor w/;

So what would be the problem ?
Buttons do line up to left,but text does not seem to get the sprintf effect...


Long live king Moshiach !
 
So the buttons are lined up but the text isn't? If you mean that the labels are centered, you may just need to put a -justify in the checkbutton command...

i.e. if your buttons like like this:
Code:
[ ]    red
[ ]   blue
[ ]  green
[ ]   cyan
[ ]  yellow
[ ] magenta

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

If that's not what you're talking about, maybe take a screenshot and link to it here?

Also, I don't know if this is a problem or not, but you don't need the parenthesis around the -variable.

Code:
-variable => \$var->{$_},

should work just fine.
 
Thanks,

What I want is the text to be lined as per sprintf statement.
[ ] red
[ ] blue
[ ] green
[ ] cyan
[ ] yellow
[ ] magenta

Tried "justify".did not help.



Long live king Moshiach !
 
Ended up using the fixed font:

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


Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top