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

I am trying to work out NoteBook tabs and how to dynamically create and destroy them, however with this particular function, I'm getting the error:

page nmap3 does not exist at /home/thefinn/workspace/Rasputin/nmap.module.pl line 57

The code is working fine other than the button to destroy the tab.

Any new hints on counting up tabs and dealing with tab methods welcome.

Thanks,
Peter.

sub nmap_scan_dialog { $tabcount++; $mytab="nmap$tabcount"; $nmap{$tabcount}=$tabsinside->add($mytab,-label => "Nmap Scan")->p +ack(); $tabsinside->Resize(); #Bug workaround. $thistab=$mytab->Frame(-background => 'black', -foreground => '#00ff00')->pack(-side => 'top', -fill => 'x'); $thistab->Label(-text => 'New Nmap Scan', -background => 'black', -foreground => '#00ff00')->pack(); $nsleft=$thistab->Frame(-background => 'black', -foreground => '#00ff00')->pack(-side=> 'left', -pady=>9, -padx => +8); $nsask1=$nsleft->Label (-text => 'Network Name:', -background => ' +black', -foreground => '#00ff00')->pack(); $nsask2=$nsleft->Label (-text => 'Target Adddress:', -background = +> 'black', -foreground => '#00ff00')->pack(); $nsask3=$nsleft->Label (-text => 'Extra Nmap Flags:', -background +=> 'black', -foreground => '#00ff00')->pack(); $nsright=$thistab->Frame(-background => 'black', -foreground => '#00ff00')->pack(-side => 'left', -pady => 2, -padx +=>15); $nsask1=$nsright->Entry (-background => '#00FF00', -foreground => 'black', -width=>12, -borderwidth=>2, -relief => 's +unken')->pack(); $nsask2=$nsright->Entry (-background => '#00ff00', -foreground => 'black', -width=>12, -borderwidth=>2, -relief => 's +unken')->pack(); $nsask3=$nsright->Entry (-background => '#00ff00', -foreground => 'black', -width=>12, -borderwidth=>2, -relief => 's +unken')->pack(); $nsbut2=$thistab->Button(-text => 'Cancel', -background => 'red', -foreground => 'black', -command => sub { $tabsinside->delete($mytab); })->pack( -side => 'right', -pady =>2, -anchor => 'w'); $nsbut1=$thistab->Button(-text => 'Start', -background => '#00FF00 +', -foreground => 'black', -command => sub { &nmap_scan() } )->pack( -side => 'right', -pady => 2, -anchor => 'w'); }

Replies are listed 'Best First'.
Re: Dynamic tab creation/destuction with Tk::Notebook
by moritz (Cardinal) on Jul 16, 2008 at 09:01 UTC
    Still no use strict; use warnings;. We recommend these not without a reason. If you seek our advice, heed it.

    And it would be nice to know what line 57 is, because the excerpt you are showing us doesn't contain that many lines.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Dynamic tab creation/destuction with Tk::Notebook
by GrandFather (Saint) on Jul 16, 2008 at 09:07 UTC

    How about crunching that down to a small runable sample that demonstrates the problem you are having?

    BTW, there seem to be a huge number of global variables there. Probably nothing to do with your problem, but good programming style avoids them like the plague. Looks like a bundle of variables are used as though they are locals but are not declared locally with my. Life time control tends to clean up a large range of subtle bugs.

    Oh, and if you are not using strictures (use strict; use warnings;) you really ought!


    Perl is environmentally friendly - it saves trees
Re: Dynamic tab creation/destuction with Tk::Notebook
by Anonymous Monk on Jul 16, 2008 at 08:57 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Dynamic tab creation/destuction with Tk::Notebook
by GrandFather (Saint) on Jul 16, 2008 at 12:07 UTC

    You may be interested in:

    use strict; use warnings; use Tk; use Tk::NoteBook; my $obj = bless {}; # Light weight object makes passing stuff around e +asier $obj->{main} = MainWindow->new( ); $obj->{notes} = $obj->{main}->NoteBook()->pack(); $obj->{notes}->add ('Master', -label => 'master')->pack(); for my $key (qw'x y z') { $obj->{"but$key"} = $obj->{main}->Button ( -text => "Add Tab $key", -command => [\&addRemove_tab, $obj, $key], )->pack(); } MainLoop(); sub addRemove_tab { my ($self, $key) = @_; if (exists $self->{"note$key"}) { $self->{notes}->delete ($key); delete $self->{"note$key"}; $self->{"but$key"}->configure (-text => "Add Tab $key"); } else { $self->{"note$key"} = $self->{notes}->add ($key, -label => $ke +y)->pack(); $self->{"but$key"}->configure (-text => "Rem Tab $key"); } }

    Perl is environmentally friendly - it saves trees
Re: Dynamic tab creation/destuction with Tk::Notebook
by zentara (Cardinal) on Jul 16, 2008 at 13:21 UTC