in reply to TK: adding notebook tabs dynamically

Thanks everyone for all the Tk help. I've changed my app to use -textvariables heavily, so the display changes as the underlying data changes. Now, all that remains is to understand / solve / engineer-around the tab issue:

I'm trying to add tabs to a notebook dynamically while the program is running, after MainLoop has started.

# silly toy example use strict; use Tk; use Tk::NoteBook; my $i=0; my $top = MainWindow->new( ); my $nb = $top->NoteBook(); $top->repeat(200, \&add_tab); &add_tab() for 1 .. 20; MainLoop(); sub add_tab { exit if $i>50; $i++; print "adding tab $i\n"; my $tab = $nb->add($i, -label => $i ); $nb->pack; }
Here, the first 20 tabs are added fine, as MainLoop hasn't started yet, but the later tabs don't show up.

Without destroying and rebuilding the entire top window, how can I add a tab to a notebook after MainLoop has started?

Thanks!

water

20041011 ysth Reparented under later duplicate

Replies are listed 'Best First'.
Re: TK: adding notebook tabs dynamically
by tachyon (Chancellor) on Oct 11, 2004 at 03:04 UTC
    use Tk; use Tk::NoteBook; my $top = MainWindow->new( ); 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( +); MainLoop(); sub delete_tab { $nb->delete($i--) } sub add_tab { $nb->add(++$i, -label => $i )->pack() }

    cheers

    tachyon