/* ChatGPT's XML example * Build it with this line: gcc main.c `pkg-config gtk+-3.0 --cflags --libs` */ #include static void on_button_clicked(GtkButton *button, gpointer user_data) { GtkTextView *textview = GTK_TEXT_VIEW(user_data); GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview); GtkTextIter start, end; gtk_text_buffer_get_start_iter(buffer, &start); gtk_text_buffer_get_end_iter(buffer, &end); gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); g_print("Text entered:\n%s", text); g_free(text); } int main(int argc, char *argv[]) { GtkBuilder *builder; GtkWidget *window, *box, *textview, *button; // Initialize GTK gtk_init(&argc, &argv); // Load the UI from the XML file builder = gtk_builder_new_from_file("example.xml"); // Get pointers to the widgets window = GTK_WIDGET(gtk_builder_get_object(builder, "window")); box = GTK_WIDGET(gtk_builder_get_object(builder, "box")); textview = GTK_WIDGET(gtk_builder_get_object(builder, "textview")); button = GTK_WIDGET(gtk_builder_get_object(builder, "button")); /* Sounds like you can also do this using CSS */ GdkRGBA color; gdk_rgba_parse(&color, "#BFBFFF"); // Parse the color value from a string gtk_widget_override_background_color(textview, GTK_STATE_FLAG_NORMAL, &color); // Connect the "clicked" signal of the button to the on_button_clicked() function g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), textview); // Show the window and start the main loop gtk_widget_show_all(window); gtk_main(); return 0; }