do code an original c99 gui , with a functionnal example demonstrating a sample widget.
- User
do code an original c99 gui , with a functionnal example demonstrating a sample widget.
Assistant
#include <gtk/gtk.h> // Define the main window GtkWidget *window; // Define the button widget GtkWidget *button; // Define the button label GtkLabel *button_label; // Define the button clicked signal handler void button_clicked(GtkButton *button, gpointer user_data) { // Get the current button label const char *label = gtk_label_get_text(button_label); // Toggle the button label between "Hello" and "Goodbye" if (strcmp(label, "Hello") == 0) { gtk_label_set_text(button_label, "Goodbye"); } else { gtk_label_set_text(button_label, "Hello"); } } // Define the main function int main(int argc, char *argv[]) { // Initialize GTK gtk_init(&argc, &argv); // Create the main window window = gtk_window_new(GTK_WINDOW_TOPLEVEL); // Set the window title gtk_window_set_title(GTK_WINDOW(window), "My GUI"); // Set the window border width gtk_container_set_border_width(GTK_CONTAINER(window), 10); // Create the button button = gtk_button_new(); // Create the button label button_label = gtk_label_new("Hello"); // Set the button label gtk_button_set_label(GTK_BUTTON(button), button_label); // Connect the button clicked signal to the button clicked signal handler g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), NULL); // Add the button to the window gtk_container_add(GTK_CONTAINER(window), button); // Show the button gtk_widget_show(button); // Show the window gtk_widget_show(window); // Run the main GTK loop gtk_main(); return 0; }This code creates a simple GUI window with a button that toggles between the labels "Hello" and "Goodbye" when clicked. It demonstrates the use of GTK to create and manage widgets, connect signals to handlers, and run the main GTK loop.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.