1

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(){
        Object(
            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.show_all();
        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

1

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

main_window.add (button_hello);
main_window.show_all();

Your Answer

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

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