Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I seem to unable to create a control in a subroutine and then immediately destroy it if a condition is true.

I assume this is a moot point by now, since the show/hide approach is best, but here it is, for posterity :)

Your code does not attempt to do that

Ignoring that for a minute, this is common for all GUI frameworks, when MainLoop is running, calling Destroy from a callback doesn't actually destroy a window immediately, it schedules it for destruction. See

Now back to the code, this will show you the error
sub button_click { $hit++; warn "hit $hit "; my $warning = Wx::StaticText->new($status, -1, "Input Error $hit " +,,[3,8]); $warning->SetForegroundColour(wxRED); if ($hit % 2) { $status->SetStatusText("", 0); $warning->Show; } else { $warning->Destroy; $status->SetStatusText("OK", 0); } warn "[\n", map({ "\t$_,\n" } $status->GetChildren ), "\] "; }
The output is
$ perl wx.904074.event.pl hit 2 at wx.904074.event.pl line 34. [ ] at wx.904074.event.pl line 46. hit 3 at wx.904074.event.pl line 34. [ Wx::StaticText=HASH(0xed4c34), ] at wx.904074.event.pl line 46. hit 4 at wx.904074.event.pl line 34. [ Wx::StaticText=HASH(0xed4c34), ] at wx.904074.event.pl line 46. hit 5 at wx.904074.event.pl line 34. [ Wx::StaticText=HASH(0xed4c34), Wx::StaticText=HASH(0xed4be4), ] at wx.904074.event.pl line 46. hit 6 at wx.904074.event.pl line 34. [ Wx::StaticText=HASH(0xed4c34), Wx::StaticText=HASH(0xed4be4), ] at wx.904074.event.pl line 46. hit 7 at wx.904074.event.pl line 34. [ Wx::StaticText=HASH(0xed4c34), Wx::StaticText=HASH(0xed4be4), Wx::StaticText=HASH(0xed4c44), ] at wx.904074.event.pl line 46. hit 8 at wx.904074.event.pl line 34.
With each iteration you're creating a new statictext, but you only Destroy it every other iteration, so the list of statictext objects keeps growing.

In reply to Re^3: How do I destroy a control after its creation in wxPerl? by Anonymous Monk
in thread How do I destroy a control after its creation in wxPerl? by ZJ.Mike.2009

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (None)
    As of 2024-04-25 01:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found