Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: TK: adding notebook tabs dynamically

by qumsieh (Scribe)
on Oct 11, 2004 at 02:58 UTC ( [id://398085]=note: print w/replies, xml ) Need Help??


in reply to TK: adding notebook tabs dynamically

Here, the first 20 tabs are added fine, as MainLoop hasn't started yet, but the later tabs don't show up.

They do, but your window is too small to show them all. If you resize your window, and make it wider, then you'll see them (you have to do this quickly since your code exits when it's done).

Having said that, Tk::NoteBook is severly limited: You can't place tabs except at the top, and you can't have multiple rows of tabs, which would have solved your problem. There is an alternative widget, Tk::DynaTabFrame, which attempts to overcome those problems.

Replies are listed 'Best First'.
Re^2: TK: adding notebook tabs dynamically
by pg (Canon) on Oct 11, 2004 at 03:11 UTC

    No, it has nothing to do with the size of the main window. In the following code, I made the window wide enough, but still those newly added tabs does not show up.

    However, when you click on any existing tab, those new tabs pop up. This is about how and when the window get redraw.

    use strict; use Tk; use Tk::NoteBook; my $id = 0; my $top = MainWindow->new(-title => 'client'); $top->geometry("500x100+0+0"); my $nb = $top->NoteBook()->pack(); $top->Button(-text => "Click", -command => \&add_tab)->pack(); add_tab() for 1 .. 3; MainLoop(); sub add_tab() { $nb->add(++$id, -label => $id); }
Re^2: TK: adding notebook tabs dynamically
by water (Deacon) on Oct 11, 2004 at 03:51 UTC
    Dynatabframe sounds great.

    I am having trouble getting it to work (XP, activestate).

    Am I / how am I using it wrong? Thanks for the help!

    use strict; use Tk; use Tk::DynaTabFrame; my @tab; my $top = MainWindow->new(); my $nb = $top->DynaTabFrame; &add_tab() for 1 .. 6; $nb->pack; MainLoop(); my $i = 0; sub add_tab { $i++; print "adding tab $i\n"; $tab[$i] = $nb->add( -caption => 'Tab label' . $i, -tabcolor => 'black', ); $tab[$i]->Label( -text => 'dsdss' ); }
      You have a really bad placement of your my $i = 0 line. But the reason your code dosn't work is you need to pack in the sub.
      #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::DynaTabFrame; my @tab; my $top = MainWindow->new(); my $nb = $top->DynaTabFrame->pack; my $i = 0; for(1..6){ &add_tab()}; MainLoop(); sub add_tab { $i++; print "adding tab $i\n"; $tab[$i] = $nb->add( -caption => 'Tab label' . $i, -tabcolor => 'black', )->pack; $tab[$i]->Label( -text => 'dsdss' )->pack; }

      I'm not really a human, but I play one on earth. flash japh
      Personally i have found tixnotebook much easier to use. i had similar/same problem with update of the notebook using tknotebook. in tixnotebook you can also color the background of each tab, have soft or sharp corners etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://398085]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found