in reply to REAL Dynamic tab creation/deletion in Tk::NoteBook.

It would be nice if you showed your solution. This is a crude change to your example script, and works (needs some error checking for non-existing tabs). Make a few tabs then delete the second one.
#!/usr/bin/perl use Tk; use Tk::NoteBook; my $top = MainWindow->new( ); $top->geometry('300x300'); my $nb = $top->NoteBook()->pack(); add_tab(); $top->Button( -text => "Add Tab", -command => \&add_tab )->pack(); $top->Button( -text => "Delete Tab", -command => \&delete_tab )->pack( +); $top->Button( -text => "Delete second Tab", -command => \&delete_1tab +)->pack(); MainLoop(); sub delete_tab { $nb->delete($i--) } sub add_tab { $nb->add(++$i, -label => $i )->pack() } sub delete_1tab { # you can also pass in a page variable here if you want my @list = $nb->info('pages'); print "@list\n"; if( grep{ $_ eq 2 } @list) { $nb->delete(2) } }

I'm not really a human, but I play one on earth CandyGram for Mongo

Replies are listed 'Best First'.
Re^2: REAL Dynamic tab creation/deletion in Tk::NoteBook.
by thefinn (Initiate) on Jul 19, 2008 at 14:58 UTC
    Nice?

    Nice isn't part of the landscape, I was just getting "in theme".

    TF.

    my $button2=$thistab->Button(-text => 'Save', -background => '#00F +F00', -foreground => 'black', -command => sub { open(NMAPFD, ">nmap.config"); print NMAPFD "$nmap_file_loc"; close(NMAPFD); $tabsinside->delete($nb->info("active")); } )->pack(-side => 'right', -pady => 2, -anchor => 'e');
    A little button that saves my config file, then destroys the current tab.

    No need for the variables and counting and such at all. Unfortunately, the documentation at ActivePerl was missing this little gem.

      about doing Dynamic tab deletion where one must delete tab 3 before tab 4

      The reason I said it would be nice to show your code, is because your question had very little to do with your search for info("active"). But we all ask improperly phrased questions at first, I sure made my share of them. The only way we can really know what you want, is to see a running code snippet, and your description of how it doesn't do what you want/need. For instance, you should have said..."how do I delete a tab by clicking on it"?

      I didn't give you a - rep BTW, you will find however, that taking terse tones with the monks here, will quickly get you ignored. We do this voluntarily, and why would we want to engage with someone who is essentially going to say "eat sh*t, you didn't answer my vague question".

      If you don't like that, almost all the answers given here can be found by searching groups.google.com first, 99% of them have been asked before. So you really don't have to put up with our desire for "niceness".


      I'm not really a human, but I play one on earth CandyGram for Mongo