in reply to Re^2: Wxperl child window destroy
in thread Wxperl child window destroy
You need to use a sizer like this
#!/usr/bin/perl -- use strict; use warnings; use Wx 0.86 qw( ); our %panel; Main( @ARGV ); exit( 0 ); sub Main { my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new( undef, -1, "Test window", [ 10, 10 +], [ 400, 600 ], Wx::wxDEFAULT_FRAME_STYLE()|Wx::wxTAB_TRAVERSAL() ); MakePanels( $frame ); my $ShowHideButton = Wx::Button->new( $frame, -1, q[Show(first)/Hi +de(second)] ); Wx::Event::EVT_BUTTON( $frame, $ShowHideButton, \&ShowHidePanels, +); $frame->SetSizer( Wx::BoxSizer->new( Wx::wxVERTICAL() ) ); $frame->GetSizer->Add( $ShowHideButton, 0, Wx::wxEXPAND() ); $frame->GetSizer->Add( $panel{first}, 1, Wx::wxEXPAND() ); $frame->GetSizer->Add( $panel{second}, 1, Wx::wxEXPAND() ); $frame->Show(1); $app->SetTopWindow($frame); $app->MainLoop; } ## end sub Main sub MakePanels { my( $frame ) = @_; $panel{'first'} = Wx::Panel->new( $frame, -1, [ -1, -1 ], [ -1, -1 + ], ); $panel{'first'}->SetBackgroundColour( Wx::wxRED() ); $panel{'first'}->Hide(); Wx::StaticText->new( $panel{'first'}, -1, 'First panel', ); $panel{'second'} = Wx::Panel->new( $frame, -1, [ -1, -1 ], [ -1, - +1 ], ); $panel{'second'}->Show(); $panel{'second'}->SetBackgroundColour( Wx::wxBLUE() ); Wx::StaticText->new( $panel{'second'}, -1, 'Second panel' ); return; } ## end sub MakePanels sub ShowHidePanels { my ( $frame, $event ) = @_; my $button = $event->GetEventObject; my $label = $button->GetLabel(); if ( $label eq 'Show(first)/Hide(second)' ) { $label = 'Hide(first)/Show(second)'; $panel{first}->Show(); $panel{second}->Hide(); $frame->GetSizer->Layout(); ##!!!! } else { $label = 'Show(first)/Hide(second)'; $panel{first}->Hide(); $panel{second}->Show(); $frame->GetSizer->Layout(); ##!!!! } $button->SetLabel($label); } ## end sub ShowHidePanels
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Wxperl child window destroy ( hide/show wxpanel in same wxframe )
by Anonymous Monk on Jun 20, 2012 at 11:44 UTC | |
by Anonymous Monk on Jun 20, 2012 at 11:58 UTC |