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

Hi Monks, I was reading the article Using advanced widgets in Perl/Tk, and following along with the exercices. The first example given is on using the NoteBook widget.

(code sligthly adapted with use strict and warnings)
#!/usr/bin/perl -w + use strict; use Tk; use Tk::NoteBook; + my $mw = MainWindow->new(); $mw->geometry( "400x100" ); my $book = $mw->NoteBook()->pack( -fill=>'both', -expand=>1 ); + my $tab1 = $book->add( "Sheet 1", -label=>"Start", -createcmd=>\&getSt +artTime ); my $tab2 = $book->add( "Sheet 2", -label=>"Continue", -raisecmd=>\&get +CurrentTime ); my $tab3 = $book->add( "Sheet 3", -label=>"End", -state=>'disabled' ); + my $starttime = ''; my $raisetime = ''; + $tab1->Label( -textvariable=>\$starttime )->pack( expand=>1 ); $tab2->Label( -textvariable=>\$raisetime )->pack( expand=>1 ); $tab3->Button( -text=>'Quit', -command=>sub{ exit; } )->pack( expand=> +1 ); + MainLoop; + sub getStartTime { $starttime = "Started at " . localtime; } sub getCurrentTime { $raisetime = " Last raised at " . localtime; $book->pageconfigure( "Sheet 3", -state=>'normal' ); }
When I execute this program, I get the error message:
bad option "expand": must be -after, -anchor, -before, -expand, -fill, + -in, -ipadx, -ipady, -padx, -pady, or -side at /usr/lib/perl5/site_p +erl/5.8.0/i386-linux-thread-multi/Tk/ line 1144. at line 18
The relevant part in is:
# Two things going on here: # 1. Add configure on the front so that we can drop leading '-' $w->Tk::pack('configure',@_); # 2. Return the widget rather than nothing return $w;

I don't feel much like meddling in self, but what else should I do?

Replies are listed 'Best First'.
Re: Bad option in
by shenme (Priest) on Apr 13, 2005 at 16:50 UTC
    But you show yourself using the wrong option "expand" rather than "-expand":
    $tab1->Label( -textvariable=>\$starttime )->pack( expand=>1 ); $tab2->Label( -textvariable=>\$raisetime )->pack( expand=>1 ); $tab3->Button( -text=>'Quit', -command=>sub{ exit; } )->pack( expand=> +1 );
    Isn't that what the error message was referring to?
      Indeed, that was the culprit. I thougth that if the code was featured in a tutorial on an IBM-site, that it would be tested and flawless, but... apparently not.
        I thougth that if the code was featured in a tutorial on an IBM-site, that it would be tested and flawless

        The change to require the '-' in front of options, occured when PerlTk upgraded to the latest TCL base. So the old PerlTk was versioned with 800 numbers, while the current version is series 804.

        So the code does run flawlessly on the Tk version, on which it was written There are many old Tk scripts like that floating around. Just go to the snippets and code sections of perlmonks and look for old Tk snippets from a few years ago. They will all give those errors if you try and run them on It's simple to fix the scripts.

        The same is true of Gtk2 scripts..the libraries are always being improved, and sometimes it breaks "old syntax".

        I'm not really a human, but I play one on earth. flash japh
        warn("err is human"x 2)'