Hi ryan,

When you create the window, assign it to a variable, then call the hide() or destroy() method on the window. Use hide if you will be reusing the window.

Here is some sample code which brings up a window with 3 buttons. The first brings up an (imaginary) error in a new window, the second closes the app, and the third closes the other window ( the one with the error ). There is also a button on the error window to close itself.

#!/usr/bin/perl -w use Gtk; use strict; my $dialog; my $label; my @errors; sub error{ if ($dialog){ $label->set_text( "ERROR " . $errors[rand @errors] ) }else{ $dialog = new Gtk::Window() ; my $bbox = new Gtk::Widget "Gtk::VBox", visible => 1, parent + => $dialog; my $button = new Gtk::Widget "Gtk::Button", label => "Close", +parent => $bbox, visible => 1; $label = new Gtk::Widget "Gtk::Label", label => $errors[rand +@errors], parent => $bbox, visible => 1 ; $button->signal_connect( "clicked", sub{ $dialog->hide }); } $dialog -> show; } sub my_quit { exit(0); } sub remote_quit{ $dialog -> hide } # or $dialog -> destroy; # if you w +ill not be opening it again init Gtk; my $window = new Gtk::Widget "Gtk::Window", type => -toplevel, title => "Error box", allow_grow => 0, allow_shrink => 0, border_width => 10, visible => 1; $window->signal_connect("destroy" => \&Gtk::main_quit); $window->signal_connect("delete_event" => \&Gtk::false); my $box1 = new Gtk::Widget "Gtk::VBox", homogeneous => 0, spacing => 5, parent => $window, visible => 1; my $bbox= new Gtk::Widget "Gtk::HButtonBox", spacing => 5, parent => $ +box1, visible => 1; my $fixed = new Gtk::Widget "Gtk::Fixed", visible => 1; $fixed->set_usize(200,50); $label = new Gtk::Widget "Gtk::Label", label => "Waiting on user input +", parent => $box1, visible => 1 ; new Gtk::Widget "Gtk::HSeparator", parent => $box1, visible => 1; my $err_btn = new Gtk::Widget "Gtk::Button", label => "Click me", clicked => "error", visible => 1, parent => $bbox; my $quit = new Gtk::Widget "Gtk::Button", label => "Quit", clicked => "my_quit", visible => 1, parent => $bbox; my $rquit = new Gtk::Widget "Gtk::Button", label => "Close the other window", clicked => "remote_quit", visible => 1, parent => $bbox; main Gtk; BEGIN{ @errors=( "Remote message: I don't like you. Go 'way.", "oh no, there is a 0 in the matrix!", "Error in matrix: Agent Smith Activated", "D'oh you've deleted the data set", "Matrix Error: You might want to take a pill", "so...lemme guess, you just clicked yes?", "no ks7 data left after removeal of zero channels", "Almost converged, you can probably stop now", "write(0,*) 'Game Over'", "I just Cannea do it Cap'n I just dinnea hea the powe +r.", "Warning: Can't get handle for AAAGH NO SWITCH IT OFF +!!! SWITCH IT OFFF!!!", "print *,'2.7182818'", "STOP PRESSING THE BUTTON GODDAMIT", + ); }

Hope this helps

thinker


In reply to Re: Closing GTK child windows via code by thinker
in thread Closing GTK child windows via code by ryan

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.