Linux and then go from the beginning GTK +-3.0 (2), gtk-3.0

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.