in reply to Tk::NoteBook issue with creating tabs under a menu

Your example was unrunable by me, but here is a working snippet that adds tabs to a notebook from a menu. You may be looking for the Resize fix.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::NoteBook; my %nbframes; my $top = MainWindow->new; $top->geometry("300x300"); my $menu = $top->Menu( -type => 'menubar' ); $top->configure( -menu => $menu ); $menu->Cascade( -label => '~Selections', -tearoff => 1, -menuitems => [ [ Button => 'dir', -command => [ \&addtab, 'dir' ] ], [ Button => 'time', -command => [ \&addtab, 'time' ] ], [ Button => 'ls', -command => [ \&addtab, 'ls' ] ], ], ); my $nb = $top->NoteBook->pack(qw/-side top -fill both -expand 1/); MainLoop; sub addtab { my $choice = shift; print $choice, "\n"; $nbframes{$choice}{'frame'} = $nb->add($choice, -label => $choice, -raisecmd => sub{ $top->update; }, -createcmd => sub{ $top->update; }, ); $nbframes{$choice}{'text'} = $nbframes{$choice}{'frame'}->Scrolled('Text',-bg=>'white')->pack( +); $nbframes{$choice}{'text'}->insert('end',time); $nbframes{$choice}{'text'}->focus(); $nb->Resize; #bug workaround }

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

Replies are listed 'Best First'.
Re^2: Tk::NoteBook issue with creating tabs under a menu
by thefinn (Initiate) on Jul 16, 2008 at 06:45 UTC
    I'm trying to make sense of the following code snippet from the example above by zentara.

    At present I'm really quite unsure how to access frame elements of dynamically created tabs.

    $nbframes{$choice}{'frame'}

    Any help appreciated.
    Peter.

      Well, Tk::Notebook->add returns a frame
      $nbframes{$choice}{'frame'} = $nb->add(...
      zentara stored it in $nbframes{$choice}{'frame'}, and later accessed it with
      $nbframes{$choice}{'frame'}->Scrolled('Text',-bg=>'white')
      so it sounds like you need to read perldsc, references quick reference