- Create
gtk_text_example.c
file:
#include <gtk/gtk.h>
// Callback function to handle the "destroy" signal
void on_destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}
int main(int argc, char *argv[]) {
// Initialize GTK
gtk_init(&argc, &argv);
// Create the main window
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GTK Text Example");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_widget_set_size_request(window, 300, 200);
// Create a label with some text
GtkWidget *label = gtk_label_new("Hello, GTK!");
// Add the label to the window
gtk_container_add(GTK_CONTAINER(window), label);
// Connect the "destroy" signal to the callback function
g_signal_connect(window, "destroy", G_CALLBACK(on_destroy), NULL);
// Show all the widgets
gtk_widget_show_all(window);
// Start the GTK main loop
gtk_main();
return 0;
}
- Compile it
gcc -o gtk_text_example gtk_text_example.c $(pkg-config --cflags --libs gtk+-3.0)
./gtk_text_example
- Run the executable output file