Hello monks,
I really need some help with this because I don't understand how I can get it to work the way I want it to.

Basically my problem is that I want to call a sub which opens a new GUI window and then destroys the current one so there is only one window open. I'll write out an example of a package and stick in a comment " $mw => 'destroy' " where I want it to happen. I don't know if this problem is trivial or not since everything I have tried hasn't worked but I'm open to suggestions (ps: i looked at perls wizard package but i didn't understand it much, but i'm sure there is a way to do this without using it.)

Here's the code:

package example; use vars qw(@ISA @EXPORT @EXPORT_OK); use Exporter; @ISA = qw(Exporter); # Symbols to autoexport (:DEFAULT tag) @EXPORT = qw( ex1 ex2 %program_config ); use vars qw(%program_config); use Tk; sub ex1(){ my $mw = MainWindow->new; $mw->title("example_window1"); $mw->MainWindow->Frame( -relief=>'groove'); $mw->minsize(600,300); my $bf = $mw-> Frame( -pady => '5') ->pack( -side => 'bottom', -anchor=>'se'); my $cancel = $bf -> Button( -relief=> 'raised', -borderwidth => '2', -text => "Cancel", -command => [$mw => 'destroy']) ->pack( -side => 'right', -padx => '20'); my $next = $bf -> Button( -relief=> 'raised', -borderwidth => '2', -text => "Next", -command => sub {ex2();}, # This is where i want it to kill the window (after the #other sub has been called) # $mw => 'destroy'] ) ->pack( -side => 'right'); my $back = $bf -> Button( -relief=> 'raised', -borderwidth => '2', -text => "Back") ->pack( -side => 'right'); MainLoop; } sub ex2(){ my $mw = MainWindow->new; $mw->title("example_window2"); $mw->MainWindow->Frame( -relief=>'groove'); $mw->minsize(600,300); my $msg = $mw -> Message(-text => "Just an example")->pack(); my $bf = $mw-> Frame( -pady => '5') ->pack( -side => 'bottom', -anchor=>'se'); my $finish = $bf -> Button( -relief=> 'raised', -borderwidth => '2', -text => "Finish", -command => [$mw => 'destroy']) ->pack( -side => 'right', -padx => '20'); MainLoop; }
PS: It also doesn't add the image if I add this code in the sub although if the code is outside a sub it seems to work fine, any ideas?
my $image = $mw->Photo( -file => "saraLogo2.gif"); $mw->Label( -image => 'image1') ->pack( -side=> "left", -anchor => 'n');
Thanks a million everyone for your help, it is much appreciated and sorry for the long post.

In reply to window destroying by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.