I made this code, but it doesn't work correctly. The window is created, but the button does not appear. I do not receive any error reports. Would anyone know why?

public class MyApp : Gtk.Application {

    public MyApp(){
            application_id: "com.github.cristianofmc.hello",
            flags: ApplicationFlags.FLAGS_NONE

    protected override void activate () {
        var button_hello = new Gtk.Button.with_label ("Click me!");
        button_hello.margin = 12;
        button_hello.clicked.connect (() => {
            button_hello.label = "Hello World!";
            button_hello.sensitive = false;
        var main_window = new Gtk.ApplicationWindow (this);
        main_window.default_height = 300;
        main_window.default_width = 300;
        main_window.title = "Hello World";
        main_window.add (button_hello);

    public static int main (string[] args) {
        var app = new MyApp ();
        return app.run (args);

enter image description here

1 Answer 1


You are showing all the window objects and then adding the button afterwards. Try:

main_window.add (button_hello);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.