help with a script



Hi everyone,

I want to write an app in perl-gtk and I'm just starting out learning the GTK part.

Can someone tell me how to close a window without closing the whole program?

Here is my sample script.
I know it's wretched. I'm just writing snippets to test out the widgets and learn more.

The part I'm trying to figure out is the line right below the string "XXXX".


That button called "forms" would pop open a list of forms for a user to do things to. Then closing that window would save the new data or perform some other act.

Thanks,

Paul Rech




#!/usr/bin/perl -w

use Gtk;
use strict;

set_locale Gtk;
init Gtk;

my $false = 0;
my $true = 1;

my $window;
my $hbox;
my $hbox2;
my $vbox;
my $frame;
my $label;
my $separator;
my $button;


# Create the window
$window = new Gtk::Window( "toplevel" );
$window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } );
$window->set_title( "Label" );

$vbox = new Gtk::VBox( $false, 5 );
$hbox = new Gtk::HBox( $false, 5 );
$hbox2 = new Gtk::HBox( $false, 5 );

$window->add( $vbox );
$vbox->pack_start( $hbox, $false, $false, 0 );
$window->border_width( 10 );

$button = new Gtk::Button( "forms");
$button->signal_connect( "clicked", \&pop_up_window  );

# Create labels and add them
$label = new Gtk::Label( "This is a Normal Label        " );
$frame = new Gtk::Frame();
$frame->add( $label );
$hbox2->pack_start( $frame, $false, $false, 0 );
$hbox2->pack_start( $button, $false, $false, 0 );
$vbox->pack_start( $hbox2, $false, $false, 0 );

$label = new Gtk::Label( "This is label #2        " );
$frame = new Gtk::Frame();
$frame->add( $label );
$vbox->pack_start( $frame, $false, $false, 0 );

$label = new Gtk::Label( "This is Label #3        " );
$frame = new Gtk::Frame();
$frame->add( $label );
$vbox->pack_start( $frame, $false, $false, 0 );

$label = new Gtk::Label( "This is Label #4        " );
$frame = new Gtk::Frame();
$frame->add( $label );
$vbox->pack_start( $frame, $false, $false, 0 );


# new part
$separator = new Gtk::HSeparator();
# 10 is the space from the next higher widget
$vbox->pack_start( $separator, $false, $true, 10 );
$separator->show();

$button = new Gtk::Button( "Quit" );
$button->signal_connect( "clicked", sub { Gtk->exit( 0 ); } );
$vbox->pack_start( $button, $true, $true, 0 );
$button->can_default( $true );
$button->grab_default();
$button->show();
# end new part


$window->show_all();

main Gtk;
exit( 0 );



sub pop_up_window {

   my $vbox;
   my $label;
   my $frame;

   # Create the window
   $window = new Gtk::Window( "dialog" );
   $window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } );
   $window->set_usize( 200, 100 );
   $window->border_width( 10 );

   $vbox = new Gtk::VBox( $false, 5 );

   $window->add( $vbox );

   $label = new Gtk::Label( "label in a popup       " );
   $frame = new Gtk::Frame();
   $frame->add( $label );
   $vbox->pack_start( $frame, $false, $false, 0 );

   $button = new Gtk::Button( "Close" );
   $vbox->pack_start( $button, $true, $true, 0 );
   # XXXX
   $button->signal_connect( "clicked", sub { return(0); } );
   $button->show();


   $window->show_all();
}


# END EXAMPLE PROGRAM



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]