#include <gtk/gtk.h>

// Callback function to change label text
static void on_button_clicked(GtkWidget *button, GtkWidget *label) {
    gtk_label_set_text(GTK_LABEL(label), "Button clicked!");
}

int main(int argc, char *argv[]) {
    GtkWidget *window;
    GtkWidget *button;
    GtkWidget *label;
    GtkWidget *box;

    // Initialize GTK
    gtk_init(&argc, &argv);

    // Create a new window
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Basic GTK Application");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);

    // Connect the "destroy" signal to gtk_main_quit to terminate the application when the window is closed
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    // Create a vertical box layout to organize widgets
    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);

    // Create a label widget
    label = gtk_label_new("Hello, GTK!");

    // Create a button widget
    button = gtk_button_new_with_label("Click Me");

    // Connect the button's "clicked" signal to the callback function
    g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), label);

    // Pack the label and button into the box
    gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);

    // Add the box to the window
    gtk_container_add(GTK_CONTAINER(window), box);

    // Show all the widgets
    gtk_widget_show_all(window);

    // Run the GTK main event loop
    gtk_main();

    return 0;
}
