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

Dear Monks,

What am I doing wrong here ...

What I am trying to do:
I am trying to popup a dialog box
that has Notebook tabs in it.

Here's the error I am getting
$ ./ Tk::Error: Failed to AUTOLOAD 'Tk::Frame::add' at ./ line 34 [\&main::callback,\{},View orders] (menu invoke)

Here's my messed up code:
#!/usr/bin/perl -w use strict; use Tk; use Tk qw(exit); use TK::Menubar; use Tk::DialogBox; use Tk::Notebook; use Tk::RoText; my $top = MainWindow->new(); my $mb = $top->Menubar; my $m1 = $mb->Menubutton ( -text => 'File' ); $m1->command( -label => 'Blah 1', -command => [sub { print "Blah 1\n"; }] ); my $m2 = $mb->Menubutton ( -text => 'Orders' ); $m2->command( -label => 'View Orders', -command => [\&callback, \$top, "View orders"] ); my $m3 = $mb->Menubutton ( -text => 'Customers' ); $m3->command( -label => 'View Customers', -command => [\&callback, \$top, "View Customers"] ); my $ro = $top->ROText()->pack( -anchor => 'n', -expand => 'both'); MainLoop(); sub callback { my $t = shift || $top; my $title = shift || "Unknown"; my $FILE1 = "whatever"; my $FILE2 = "something"; my $dd = $$t->DialogBox( -title => $title ); #->Frame(); my $d = $dd->Frame()->pack(); my $n = $d->NoteBook()->pack( -expand => 0, -fill => 'x' ); #, + -in => $$t); my $p = $n->add( 'page1', -label => $title ); my $e1 = $p->add( 'Entry', -width => 60, -textvariable => \$FILE1 )->pack(); my $b1 = $p->add( 'Button', -width => 10, -text => 'File 1', -command => [sub { print "$FILE1\n"; }]); my $b2 = $p->add( 'Button', -width => 10, -text => 'Details', -command => [\&callback, \$d, "Details"] ); $e1->pack(); $b1->pack(); $b2->pack(); $d->Show(); }

Is it just not possible to do this?
I am sure there is a way ... please help!

Replies are listed 'Best First'.
Re: Tk::NoteBook tabs in a Tk::Dialog question
by buckaduck (Chaplain) on Apr 23, 2002 at 20:27 UTC
    I think that your code:
    my $d = $dd->Frame()->pack(); my $n = $d->NoteBook()->pack( -expand => 0, -fill => 'x' );
    should probably be something more like (untested):
    my $d = $dd->add(Tk::Frame); $d->pack; my $n = $d->add(Tk::NoteBook); $n->pack( -expand => 0, -fill => 'x' );
    The Tk widgets are not method names, you have to pass the widget names to the add() method. Also, I believe that you should assign the widget to a variable first and then pack() it.


      Buckaduck.... ....i dont know if its worth mentioning it, because his code doesnt have the same error, however it does have the same symptom as mine.... It CAN work like this:
      use Tk; use Tk::NoteBook; my $mw = MainWindow->new(-width => 40, -height => 50); $mw->title("Ventana Principal"); $mw->Label(-text => "Uso de pack")->pack; $FrameFon = $mw->Frame(-relief => 'raised')->pack(-side => 'bottom', f +ill => 'x', -expand => 1); $Libreta = $FrameFon->NoteBook(); $Libreta->pack(-side => 'top'); $Libreta->add("Pagina1", -label =>"Configuracion"); $Libreta->add("Pagina2", -label => "Logs"); MainLoop;
      ...but mine didnt work because i was writing Notebook instead of NoteBook.... :">
      Heatseeker Cannibal
Re: Tk::NoteBook tabs in a Tk::Dialog question
by graff (Chancellor) on Apr 24, 2002 at 04:02 UTC
    Um, so... which line is line #34 in your code?

    (Since the <code> tag does not, by itself, number the lines, it will be helpful in your posting if you add a comment at the line that is referred to in a quoted error trace, to make that clear.)

    Let me guess that it might be this line:

    my $e1 = $p->add( 'Entry',
    I'm guessing it's this one, because the error says you're trying to call an "add" method on a "Frame" widget, which has no such method; and while I have never used a NoteBook widget before, I wouldn't be surprised to look in its docs and discover that the widget you get back when you call the "add" method on a NoteBook is ... a Frame, which would make your "$p" a frame widget and raise the error. You should look that up.

    As for buckaduck's reply, it is of course fine (and frequent practice) to both invoke and pack a widget at "the same time", as you do in your original code. Don't worry about that.