Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Reseting 'caption' of Tabbed Frame

by merrymonk (Hermit)
on Jun 02, 2011 at 14:42 UTC ( [id://907809]=perlquestion: print w/replies, xml ) Need Help??

merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I am sure that this should be simple but after some time looking at it I cannot see what is wrong !
I have set up a tabbed frame and using the –caption option given it a ‘title’.
I then try to:
1. Retrieve this but nothing is returned;
2. Reset it using configure but get the message that –caption is not an option.
Can someone give me a clue as to why this is wrong.
The Perl and full output is given below.
# tabframe-m use strict "vars"; use Tk; use Tk::TabFrame; my ($a_tbfr, $tab_mw, $b_tbfr, $frame_wg, %lbwg, %entrywg); my ($label_text, $CurrentSelection, $child, $childb, $childc, $childd) +; my ($CurrentSelectionC, $CurrentSelectionR, %tabwg, $tabwg_item, $curr +ent_product, $gen_str); my ($gen_intials, $gen_str, $gen_whog, $gen_whoa, $gen_whob, $gen_whoc +, $pb_intials, $pa_intials, $pb2_intials, $j, $j_str); my ($lb_str, $en_str, $cap_retrieved, $lab_retrieved, $lb_text, $text_ +retrieved, $top_wg); $current_product = 'unset'; $tab_mw = MainWindow->new; $top_wg = $tab_mw->Label(-text => 'Caption query')->grid(-row => 0); $text_retrieved = $top_wg->cget(-text); print "top_wg $top_wg retrieved text $text_retrieved\n"; $a_tbfr = $tab_mw->TabFrame ( -font =>'-adobe-times-medium-r-bold--14', -tabcurve =>4, -padx => 10, -pady => 10, -width => 50 ); $a_tbfr->grid ('-row' => 1); for($j = 1; $j <= 1; $j ++) { $j_str = "Tab " . $j; # this sets the caption which can be seen $tabwg{$j_str} = $a_tbfr->Frame ( -caption => $j_str, ); # this trys to retrieve the caption but nothing is returned $cap_retrieved = $tabwg{$j_str}->cget( -caption); print "widget name $j_str wg $tabwg{$j_str} caption set $j_str ret +rieved [$cap_retrieved]\n"; $lb_str = "Tab " . $j . '_Label'; $lb_text = "Text in Label in $j_str"; $lbwg{$j_str} = $tabwg{$j_str}->Label(-text => $lb_text, -width => 100)->grid(-row => 2, -column=>0); $lab_retrieved = $lbwg{$j_str}->cget( -text); print "text given $lb_text wg $tabwg{$j_str} retrieved $lab_retrie +ved\n"; $en_str = "Tab " . $j . '_Entry'; $tabwg{$j_str}->Entry (-text => $en_str, -width => 20)->grid(-row => 3, -column=>0); } foreach $tabwg_item (keys %tabwg) { print "item $tabwg_item wg $tabwg{$tabwg_item}\n"; # this trys to reset the caption for the tabbed frame child $tabwg{$tabwg_item}->configure(-caption => 'New Caption'); } print "\n"; MainLoop;
Contents of MS-DOS screen
top_wg Tk::Label=HASH(0x194b508) retrieved text Caption query
widget name Tab 1 wg Tk::Frame=HASH(0x1a89968) caption set Tab 1 retrieved []
text given Text in Label in Tab 1 wg Tk::Frame=HASH(0x1a89968) retrieved Text in Label in Tab 1
item Tab 1 wg Tk::Frame=HASH(0x1a89968)
Tk::Error: Can't set -caption to `New Caption' for Tk::Frame=HASH(0x1a89968): unknown option "-caption" at C:/.../perl5/site/lib/Tk/Configure.pm line 45.
at C:/.../perl5/site/lib/Tk/Derived.pm line 294
Tk callback for event
Tk callback for .
Tk callback for .tabframe.buttonFrame
Tk callback for .tabframe.magicFrame
Tk callback for .tabframe
Tk callback for .tabframe
Tk callback for .tabframe.tabChildFrame
Tk callback for .tabframe.tabChildFrame.frame
Tk callback for .tabframe.buttonFrame.button_Tk_Frame_HASH_0x1a89968_
Tk callback for .tabframe
Tk callback for .tabframe.buttonFrame.button_Tk_Frame_HASH_0x1a89968_.frame
Tk callback for .tabframe.buttonFrame.button_Tk_Frame_HASH_0x1a89968_.frame1
Tk callback for .tabframe.buttonFrame.button_Tk_Frame_HASH_0x1a89968_.frame2
Tk callback for .tabframe.buttonFrame.button_Tk_Frame_HASH_0x1a89968_.frame3
Tk callback for .tabframe.buttonFrame.button_Tk_Frame_HASH_0x1a89968_.frame4
Tk callback for .tabframe.buttonFrame.button_Tk_Frame_HASH_0x1a89968_.frame5
Tk callback for .tabframe.tabChildFrame.frame
Tk callback for .tabframe.tabChildFrame.frame
Tk::Derived::configure at C:/.../perl5/site/lib/Tk/Derived.pm line 306
Can't set -caption to `New Caption' for Tk::Frame=HASH(0x1a89968): unknown option "-caption" at C:/.../perl5/site/lib/Tk/Configure.pm line 45.
at C:/.../perl5/site/lib/Tk/Derived.pm line 294

Replies are listed 'Best First'.
Re: Reseting 'caption' of Tabbed Frame
by thundergnat (Deacon) on Jun 02, 2011 at 17:49 UTC

    Looks like TabFrame doesn't set up any accessors to allow you to easily change the tab title. You'll need to go spelunking around through the subwidgets to access them after they have been created.

    Here's a short demo based on your script with a lot of extraneous stuff cut out.

    use strict; use warnings; use Tk; use Tk::TabFrame; my $tab_mw = MainWindow->new; my $top_wg = $tab_mw->Label( -text => 'Caption query' )->grid( -row => + 0 ); my $a_tbfr = $tab_mw->TabFrame( -font => '-adobe-times-medium-r-bold--14', -tabcurve => 4, -padx => 10, -pady => 10, -width => 50 ); $a_tbfr->grid( '-row' => 1 ); my ( %tabwg, %lbwg ); for my $j ( 1 .. 2 ) { # this sets the tab title which can be seen my $j_str = "Tab $j"; $tabwg{$j_str} = $a_tbfr->Frame( -caption => $j_str, ); # Find the reference to this particular button (Data::Dumper is yo +ur friend) my $this_button = $a_tbfr->{'SubWidget'}{'ButtonFrame'}{'SubWidget'} { 'Button_' . $tabwg{$j_str} }->Subwidget('Button'); # Get tab title my $tab_title = $this_button->cget('-text'); print "Tab title for tab $j - retrieved [$tab_title]\n"; my $new_title = $tab_title; $new_title =~ s/Tab/New/; # Change tab title $this_button->configure( -text => $new_title ); my $lb_str = "Tab " . $j . '_Label'; my $lb_text = "Text in Label in $j_str"; $lbwg{$j_str} = $tabwg{$j_str}->Label( -text => $lb_text, -width => 100 )->grid( -row => 2, -column => 0 ); my $lab_retrieved = $lbwg{$j_str}->cget( -text ); #print "text given $lb_text wg $tabwg{$j_str} retrieved $lab_retri +eved\n"; my $en_str = "Tab " . $j . '_Entry'; $tabwg{$j_str}->Entry( -text => $en_str, -width => 20 )->grid( -row => 3, -column => 0 ); } MainLoop;

    Not particularly pretty, but it will get the job done.

      Thanks for that. I have never "spelunked around through the subwidgets" so I guess it is unlikely I would ever
      have worked this one out!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://907809]
Approved by marto
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-04-18 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found