Skip to content

Instantly share code, notes, and snippets.

@itsuki-hayashi
Last active July 25, 2023 04:24
Show Gist options
  • Save itsuki-hayashi/f0c532c353abb8d5125232667b988a18 to your computer and use it in GitHub Desktop.
Save itsuki-hayashi/f0c532c353abb8d5125232667b988a18 to your computer and use it in GitHub Desktop.
GTK4 Hello world in Perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use v5.38;
use Glib::Object::Introspection;
Glib::Object::Introspection->setup(
basename => 'Gio',
version => '2.0',
package => 'Gio');
Glib::Object::Introspection->setup(
basename => 'Gtk',
version => '4.0',
package => 'Gtk');
Glib::Object::Introspection->setup(
basename => 'Gdk',
version => '4.0',
package => 'Gdk');
Glib::Object::Introspection->setup(
basename => 'Gsk',
version => '4.0',
package => 'Gsk');
my $app = Gtk::Application->new('org.gtk.HelloApp', 'flags-none');
# When the application is launched
$app->signal_connect(activate => sub {
# create a new window
my $win = Gtk::ApplicationWindow->new($app);
# with a button in it
my $btn = Gtk::Button->new_with_label('Hello World!');
# which closes the window when clicked
$btn->signal_connect(clicked => sub { $win->close(); });
$win->set_child($btn);
$win->present();
});
# Run the application
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment