Snippet. Vala, Gtk Button Example

This snippet shows how to work with buttons in Vala.

using Gtk;

Gtk.Button button = new Gtk.Button();
button.set_label("Click me");
button.clicked.connect(button_clicked);

void button_clicked () {
    Gtk.MessageDialog dialog = new Gtk.MessageDialog(null,Gtk.DialogFlags.MODAL,Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "You clicked the button!");
    dialog.set_title("Button clicked");
    dialog.run();
    dialog.destroy();
}

Result



Updated on: 21 Nov 2024