0

这段代码向我展示了 xubuntu 21.04 表单,大小(400px 宽度 + 400px 高度)和一个按钮。

如何在此代码中添加两个按钮?

#include <gtk/gtk.h>

static void activate(GtkApplication *app, void *user_data) {
    GtkWidget *window = gtk_application_window_new(app);

    gtk_window_set_child(GTK_WINDOW(window), gtk_label_new("Hello World!"));
    gtk_window_present(GTK_WINDOW(window));

    gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);

    // Create a new button
    GtkWidget *button = gtk_button_new_with_label ("press 123");
    gtk_window_set_child (GTK_WINDOW (window), button);
    // When the button is clicked, close the window passed as an argument
 g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_close), window);
}

int main(int argc, char *argv[]) {
    g_autoptr(GtkApplication) app = gtk_application_new(NULL, G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
 
    return g_application_run(G_APPLICATION(app), argc, argv);
}
4

0 回答 0