Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

more than one DynaTabFrame

by liamlrb (Acolyte)
on Nov 17, 2010 at 12:21 UTC ( #871982=perlquestion: print w/replies, xml ) Need Help??
liamlrb has asked for the wisdom of the Perl Monks concerning the following question:

should be simple ( sbs ). Just want to have two separate sets of tabbed frames. this code is only showing the last tabbed frame that had something packed in it. so in this case it would show a blank tab for what should be the B tab and under that a normal A tab with the label "A" in it
use Tk; use Tk::DynaTabFrame; $mw = MainWindow->new; $parent_frame_b = $mw->Frame ()->pack(); $wnd_b = $parent_frame_b->DynaTabFrame ()->pack( ); $frm_b = $wnd_b->add( 'B', -hidden => 0, -caption => 'B')->pack( ) +; $frm_b->Label( -text => "B" )->pack( ); $parent_frame_a = $mw->Frame ()->pack(); $wnd_a = $parent_frame_a->DynaTabFrame ( )->pack( ); $frm_a = $wnd_a->add( 'A', -hidden => 0, -caption => 'A')->pack( ) +; $frm_a->Label( -text => "A" )->pack( ); MainLoop;

Replies are listed 'Best First'.
Re: more than one DynaTabFrame
by zentara (Archbishop) on Nov 17, 2010 at 13:59 UTC
    Here is an example using plain Notebook tabs. I would guess that DynaTabFrame would work just as well as Notebook, just substitute it in.

    The main problem with these widgets, is you need to pack them after all of them are constructed, so the window manager knows how much size to allocate, otherwise they get set to a small size, and get crushed. I used many scalars in this script, it probably should use a hash for storing refs... like $myhash{'frame1'}{'nb'}{'page5'}{etc}

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::NoteBook; use Tk::Pane; use Tk::LabFrame; my $mw = new MainWindow; $mw->geometry("500x500"); my $pane = $mw->Scrolled('Pane', -scrollbars=>'osoe', sticky=>'nwse'); my $mf = $pane->Frame; my $nb = $mf->NoteBook(-width=>300); my $nb1 = $nb->add("page1", -label=>"Page 1"); my $nb2 = $nb->add("page2", -label=>"Page 2"); my $nb3 = $nb->add("page3", -label=>"Page 3"); my $nb4 = $nb->add("page4", -label=>"Page 4"); my $nbf1=$nb1->Scrolled('Text', -scrollbars=>'se')->pack; $nbf1->insert('end', "Tab 1"); my $nbf2=$nb2->Label(-text=>"Tab 2")->pack; my $nbf3=$nb3->LabFrame(-label=>"Tab 3", -labelside=>"acrosstop")->pac +k; my $nbf3b1=$nbf3->Radiobutton(-text=>"Radiobutton1")->pack(-anchor=>"n +w"); my $nbf3b2=$nbf3->Radiobutton(-text=>"Radiobutton2")->pack(-anchor=>"n +w"); my $nbf4=$nb4->Canvas(-background=>"yellow")->pack; $nbf4->createText(30,40, -text=>"Tab 4"); # second set my $mfz = $pane->Frame; my $nbz = $mfz->NoteBook(-width=>300); my $nb1z = $nbz->add("page1", -label=>"Page 1"); my $nb2z = $nbz->add("page2", -label=>"Page 2"); my $nb3z = $nbz->add("page3", -label=>"Page 3"); my $nb4z = $nbz->add("page4", -label=>"Page 4"); my $nbf1z=$nb1z->Scrolled('Text', -scrollbars=>'se')->pack; $nbf1z->insert('end', "Tab 1"); my $nbf2z=$nb2z->Label(-text=>"Tab 2")->pack; my $nbf3z=$nb3z->LabFrame(-label=>"Tab 3", -labelside=>"acrosstop")->p +ack; my $nbf3b1z=$nbf3z->Radiobutton(-text=>"Radiobutton1")->pack(-anchor=> +"nw"); my $nbf3b2z=$nbf3z->Radiobutton(-text=>"Radiobutton2")->pack(-anchor=> +"nw"); my $nbf4z=$nb4z->Canvas(-background=>"yellow")->pack; $nbf4z->createText(30,40, -text=>"Tab 4"); #pack them up $nb->pack; $mf->pack; $nbz->pack; $mfz->pack; $pane->pack(-expand=>1, -fill=>'both'); MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
          Every time I come and look around or ask a question, your replying.... Thank you
    Re: more than one DynaTabFrame
    by kcott (Chancellor) on Nov 17, 2010 at 13:07 UTC

      I just ran this code unaltered.

      Both tabs are shown with the text "A" or "B" as you've coded it here.

      Both have the Labels you've packed - not just the last one.

      You are correct about "A" showing under "B" - that's the order you packed them in.

      You are incorrect with respect to "... so in this case it would show a blank tab for what should be the B tab ...". Why did you think that would be the case when you've provided text for both tabs?

      Perhaps there's some confusion because everything is called just "A" or "B" - try "Tab A" and "Label A", for instance, so that you can see more clearly what is going on.

      I strongly recommend that you do not use global variables throughout your code!

      You should add use strict; and use warnings; to the top of your code.

      -- Ken

        Hi Ken, thanks for checking it out for me... This was the smallest code example that shows my problem I could write and not actual production code... I am still getting the same indications! I am running Perl v5.10.1 and Tk 804 and dynatabframe .23 what are you running?

          I have Tk 804.029 and Tk::DynaTabFrame 0.23; I'm running Perl 5.12.0 - got the same results I reported on both Cygwin (cygwin-thread-multi-64int) and Windows XP (MSWin32-x86-multi-thread).

          -- Ken

    Re: more than one DynaTabFrame
    by Khen1950fx (Canon) on Nov 17, 2010 at 13:58 UTC
      A slighty different way:
      #!/usr/bin/perl use strict; use warnings; use Tk::DynaTabFrame; my $mw = MainWindow->new(); my $dtf = $mw->DynaTabFrame( -font => 'Sans 8', -tabclose => 1, ) ->pack(-side => 'top', -expand => 0, -fill => 'both'); my $buttons1 = $mw->Frame() ->pack(-side => 'top', -fill => 'x', -expand => 0, -pady => 0); my $buttons2 = $mw->Frame() ->pack(-side => 'top', -fill => 'x', -expand => 0, -pady => 0); $buttons1->Button (-text => ' ')->pack; $buttons2->Button (-text => 'A')->pack; Tk::MainLoop();

    Log In?

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: perlquestion [id://871982]
    Approved by Corion
    [marto]: this puts me in mind of Understand, which is well worth the read IMHO

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (8)
    As of 2018-01-17 13:38 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (200 votes). Check out past polls.