Linux and then go from the beginning GTK +-3.0 (2), gtk-3.0
Creating only one blank window is not enough. Next we will add a button for the created window.
Hello, World! For example.
First, create a source file: example2.c with the following content.
# Include <gtk/gtk. h> // The function called after the button is clicked. It is used to output hello, worldstatic void print_msg (GtkWidget * button, gpointer data) {printf ("Hello, world! \ N ");} static void activate (GtkApplication * app, gpointer data) {GtkWidget * win; // declare a button GtkWidget * button; // declare a box container, used to hold buttons and control the size of GtkWidget * button_box; win = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (win), "Button test"); struct (GTK_WINDOW (win), 200,200 ); // create a box container and set horizontal placement of button_box = gtk_button_box_new (container); // container // include the box container into the window gtk_container_add (GTK_CONTAINER (win), button_box ); // create a button with the "My button" label button = gtk_button_new_with_label ("My button"); // connect the signal. After clicking the button, call the print_msg function g_signal_connect (button, "clicked", G_CALLBACK (print_msg), NULL );
// Put the button in the box container gtk_container_add (GTK_CONTAINER (button_box), button); // display the window and all its controls gtk_widget_show_all (win);} int main (int argc, char ** argv) {GtkApplication * app; int app_status; app = gtk_application_new ("org. gtk. exmple ", G_APPLICATION_FLAGS_NONE); g_signal_connect (app," activate ", G_CALLBACK (activate), NULL); app_status = g_application_run (G_APPLICATION (app), argc, argv ); g_object_unref (app); return app_status ;}
The running result is as follows: