How can I create a widget without it being placed on its parent?
Here's a minimal example.
package MyApp;
use strict;
use warnings;
use Wx;
use base 'Wx::App';
sub OnInit {
my ($self) = @_;
my $frame
= Wx::Frame->new( undef, -1, 'Test', [ -1, -1 ], [ 250, 150 ], );
my $sizer = Wx::GridBagSizer->new( 0, 0 );
my $btn1 = Wx::Button->new( $frame, -1, '1' );
my $btn2 = Wx::Button->new( $frame, -1, '2' );
$sizer->Add( $btn1, Wx::GBPosition->new( 2, 2 ) );
$frame->SetSizer($sizer);
$frame->Show(1);
1;
}
package main;
MyApp->new->MainLoop;
This yields
I want only what is placed in the sizer (button 1) to show.
You can hide things by calling $thing->Show(0)
. I added:
$btn2->Show(0);
The layout is still kinda funny because the space for the widget is still there—it's just not visible. So, it's still "placed". Maybe you want to create the control somewhere else that you can size on its own.
You have to hide the widget before the call to Layout
.