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

Given that this example is not dynamic but sequential Tab deletion Re: TK: adding notebook tabs dynamically, how does one go about doing Dynamic tab deletion where one must delete tab 3 before tab 4?

Perhaps there's a way to call the current tab or parent frame somehow that I'm not aware of?

Or perhaps an easier method?

Thanks,
Peter.

Update:
It is nice to see the -2 Rep for asking the question of you helpful guys.
At least you're consistent.

I actually went to CPAN for documentation on NoteBook and found the info("focus") method which was missing from the ActivePerl documentation I had been reading at the time.

NoteBook @ActivePerl

So the problem was actually very easy to solve once one has the right documentation in any case.

Thanks for all the great help.

  • Comment on REAL Dynamic tab creation/deletion in Tk::NoteBook.

Replies are listed 'Best First'.
Re: REAL Dynamic tab creation/deletion in Tk::NoteBook.
by zentara (Cardinal) on Jul 16, 2008 at 13:08 UTC
    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
      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
Re: REAL Dynamic tab creation/deletion in Tk::NoteBook.
by oko1 (Deacon) on Jul 16, 2008 at 14:44 UTC
    > Update:
    > It is nice to see the -2 Rep for asking the question of you helpful guys.
    > At least you're consistent.
    

    There's a simple reason for this: you've maxed out the PerlMonks JerkMeter by being rude to some of the smartest, most helpful people in this forum. Once you do that, all your posts are automatically marked '-5' (so you should be grateful to the people who up-voted you) and a large group of Monks are chosen to laugh at you (quite pleasant duty, that.) Oh, and your name here is shown as 'Mud' rather than 'thefinn' for a fixed period. The JM is a very smart piece of code...

    I suggest you go away until you're forgotten, and use the interval to learn polite posting habits as well as group protocol. When you're fit to associate with people again, feel free to come back; we'll still be here, helping people who ask politely and informatively.

    Oh, and - have a nice day. (thefinn--)

    Update: fixed the misspelled username.

    
    -- 
    Human history becomes more and more a race between education and catastrophe. -- HG Wells