Thanks everyone for all the Tk help.

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( -title => 'client', ); 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

UPDATE:
Thought I could solve the problem by preallocating a set of tabs for later use. Sure, but after MainLoop has started, if I change the options on the preallocated tab, those changes don't seem to be visible. So this preallocation scheme (as least as I implemented it) does not work. Suggestions, wise monks?

Considered: kelan dup of 398068
Unconsidered: ysth enough keep votes, positive rep - Keep/Edit/Delete: 2/2/20


In reply to TK: adding notebook tabs dynamically by water

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.