Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:


Dear Friends,
I wrote a perl program using perl Tk,

I used Text widgets and I handling the following three options


1. Left Justify
2. Right Justify
3. Center
for me the -justify option is throwing erro. I faced some problems using the -justify option The following error I got
Tk::Error: Bad option `-justify' at Editor.pl line 82.
Tk callback for .text
Tk callback for .#menu.#menu#font.#menu#font#juesify
Tk::__ANON__ at /usr/lib/perl5/Tk.pm line 247
Tk::Menu::Invoke at /usr/lib/perl5/Tk/Menu.pm line 531
<ButtonRelease>
(command bound to event)
what is the problem how can I solve this problem?
Thanks in advance. by Sugumar.T.R
  • Comment on Perl tk [ Tk::Text -justify option is not working

Replies are listed 'Best First'.
Re: Perl tk [ Tk::Text -justify option is not working
by zentara (Cardinal) on Feb 17, 2010 at 13:31 UTC
    You are probably using justify wrong. In a text widget, it is a tag option. Does this work?
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Text; use strict; my $mw = MainWindow->new; my $t = $mw->Scrolled('Text', -scrollbars=> 'se', -height=> 5, -background =>'white', -wrap => 'none') ->pack(-side=>'bottom', -fill=> 'both', -expand=> '1'); $t->tagConfigure('right', -justify => 'right'); $t->insert('end',"This is a right justified, none wrapping text.\n",'r +ight'); $t->insert('end','Try to type some text over the left edge of the wind +ow here: ','right'); $t->focus; MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
      Hi.. I used Text widget so I wrote my code like.
      $align -> command(-label =>"Left",-command=>sub { #$txt->configure( -justify =>'left'); $txt->tagConfigure('left', -justify => 'left'); } ); $align -> command(-label =>"Right",-command=>sub { #$txt->configure(-justify=>'right'); $txt->tagConfigure('right', -justify => 'right'); } ); $align -> command(-label =>"Center",-command=>sub { #$txt->configure(-justify=>'center'); $txt->tagConfigure('center', -justify => 'center'); } );

      but the text in the Text widget are not aligned to left,right or center.
      How can I achieve the text alignment option in Text widget?

        I don't see a running code example, but the Tk demo "widget" has a text example which shows centered tag usage.
        $t->tag(qw/configure center -justify center/);

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku
Re: Perl tk [ Tk::Text -justify option is not working
by Anonymous Monk on Feb 17, 2010 at 07:11 UTC
    what is the problem how can I solve this problem?

    The problem is you're passing a justify option to something that doesn't take a justify option, as the error message tells you.

    $ perldoc Tk::Menu |grep -i justify
Re: Perl tk [ Tk::Text -justify option is not working
by Anonymous Monk on Feb 17, 2010 at 07:43 UTC
    The problem may exist in the way you wrote the code to do this and which you haven't shown!,show how you used the option by posting the part of your code that demonstrate this problem....