This tutorial will demonstrate how to:
create a small "Hello, World" application using GTK+
make the
how to set up the build system
Gtk.Application initializes GTK+. It also connects the
We can start building our first window. We do this by creating a variable called window and assigning it a new Gtk.ApplicationWindow.
We give the window a title using set_title
. The title can be any string you want it to be. To be on the safe side, it's best to stick to UTF-8 encoding.
Now we have a window which has a title and a working "close" button. Let's add the actual "Hello World" text.
Finally, we create and run the application:
Gtk.ApplicationWindow can only hold one widget at a time. To construct more elaborate programs you need to create a holder widget like Gtk.Grid inside the window, and then add all the other widgets to it.
The complete file:
To run this application, first save it as hello-world.vala. Then open Terminal, go to the folder where your application is stored.
Compile the program:
Run the program:
Running applications from the Terminal is useful at the beginning of the application making process. To have fully working application integration in GNOME 3 requires a desktop launcher. For this you need to create a
The example shows you the minimum requirements for a .desktop.in
file.
Now let's go through some parts of the .desktop.in
file.
The application name.
A short description of the application.
Specifies a command to execute when you choose the application from the menu. In this example exec just tells where to find the
Specifies whether the command in the Exec key runs in a terminal window.
To put your application into the appropriate category, you need to add the necessary categories to the Categories line. More information on the different categories can be found in the menu specification.
In this example we use an existing icon. For a custom icon you need to have a .svg file of your icon, stored in
To make your application truly a part of the GNOME 3 system you need to install it with the help of autotools. The autotools build will install all the necessary files to all the right places.
For this you need to have the following files:
After the
Information users should read first. This file can be blank.
When you have the