in reply to Wxperl child window destroy

In the panel that needs to change, store each set of widgets in their own panels and ->Show() and ->Hide() them as needed.

Replies are listed 'Best First'.
Re^2: Wxperl child window destroy
by Anonymous Monk on Jun 20, 2012 at 09:48 UTC
    I'm trying something similar but hiding and showing pannels is not working. If I create two panels, hide the first one and show the second one only a small piece of the first panel is shown. I think the first panel is overlapping in some way. How do I fix this? See included code.
    #!perl -w use Wx; ####################################### # # package MyApp; # # ####################################### use strict; use vars qw(@ISA); @ISA = qw(Wx::App); # the OnInit method is called sub OnInit { my($this) = @_; my($frame) = MyFrame->new( undef, -1, "Test window", [600, 400], [ +400, 600] ); $frame->Show(1); $this->SetTopWindow($frame); # if OnInit doesn't return true, the application exits immediately +. return 1; } ####################################### # # package MyFrame; # # ####################################### # # This package overrides Wx::Frame, and allows us to put controls # in the frame. # use strict; use vars qw(@ISA); @ISA = qw(Wx::Frame); sub new { my( $class ) = shift; my( $this ) = $class->SUPER::new( @_ ); # starter variables for 'x' and 'y' position my $xstart = 5; my $ystart = 5; my %panel; # Create panel: 'First' $panel{'first'} = Wx::Panel->new( $this, -1, ); # create panel 1 static text Wx::StaticText->new( $panel{'first'}, -1, 'First panel', [$xstart, $ystart] ); $panel{'first'}->Hide(); + # Create panel: 'Second' $panel{'second'} = Wx::Panel->new( $this, -1, ); # create panel 2 static text Wx::StaticText->new( $panel{'second'}, -1, 'Second panel', [$xstart, $ystart] ); $panel{'second'}->Show(); return $this; } package main; my($app) = MyApp->new(); $app->MainLoop();

      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
        Thank you for the quick answer! :)

        I try to understand the 'GetSizer' method but can't find any information (http://docs.wxwidgets.org/2.8.4/wx_classesbycat.html#classesbycat).

        Do you have link where 'Getsizer' is explained?