[ create a new paste ] login | about

Link: http://codepad.org/9b14DmH8    [ raw code | output | fork ]

Perl, pasted on Oct 31:
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

# Our new improved callback.  The data passed to this function
# is printed to stdout.
sub callback
	my ($button, $data) = @_;
	print "Hello again - $data was pressed\n";

# another callback
sub delete_event
	return FALSE;

# Create a new window
$window = Gtk2::Window->new('toplevel');

# This is a new call, which just set the title for our
# new window to "Hello Buttons!"
$window->set_title("Hello Buttons!");

# Here we just set a handler for the delete_event that immediately
# exits GTK.
$window->signal_connect(delete_event => \&delete_event);

# Sets the border width of the window.

# We create a box to pack widgets into.  This is described in detail
# in the "packing" section. The box is not really visible, it
# is just used as a tool to arrange widgets.
$box1 = Gtk2::HBox->new(FALSE, 0);

# Put the box into the main window.

# Creates a new button with the label "Button 1".
$button = Gtk2::Button->new("Button 1");

# Now when the button is clicked, we call the "callback" function
# with the string "button 1" as its argument.
$button->signal_connect(clicked => \&callback, 'button 1');

# Instead of Gtk2::Container::add, we pack this button into the invisible
# box, which has been packed into the window.
$box1->pack_start($button, TRUE, TRUE, 0);

# Always remember this step, this tells GTK that our preparation for this
# button is complete, and it can now be displayed.

# Do the same steps again to create a second button.
$button = Gtk2::Button->new("Button 2");

# Call the same callback function with a different argument, passing the string
# "button 2" instead.
$button->signal_connect(clicked => \&callback, 'button 2');

$box1->pack_start($button, TRUE, TRUE, 0);

# The order in which we show the buttons is not really important, but I
# recommend showing the window last, so it all pops up at once.




# Rest in main and wait for the fun to begin!


Can't locate Glib.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i486-linux /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i486-linux /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .) at line 2.
BEGIN failed--compilation aborted at line 2.

Create a new paste based on this one