Linux from the beginning again gtk+-3.0 (ii)

Source: Internet
Author: User
Tags gtk

Just creating a blank window is not enough, let's add a button to the window we created.

With hello,world! As an example.

First create a source file: The example2.c content is as follows.

#include <gtk/gtk.h>//the function that is called after the button is clicked for output Hello,worldStatic voidPrint_msg (Gtkwidget *button, gpointer data) {printf ("Hello, world!\n.");}Static voidActivate (Gtkapplication *app, gpointer data) {Gtkwidget*win; //Declare a buttonGtkwidget *button; //Declare a box container to hold the button, control the sizeGtkwidget *Button_box; Win=gtk_application_window_new (APP); Gtk_window_set_title (Gtk_window (Win),"Button Test"); Gtk_window_set_default_size (Gtk_window (Win), $, $); //Create a box container and set a horizontal placementButton_box = Gtk_button_box_new (gtk_orientation_horizontal);//Gtk_orientation_horizontal//include the box container into the windowGtk_container_add (Gtk_container (Win), Button_box); //Create a button with the label "My button"button = Gtk_button_new_with_label ("My Button"); //connect the signal so that the PRINT_MSG function is called when the button is clickedG_signal_connect (Button,"clicked", G_callback (print_msg), NULL);
 
//put the button in the box containerGtk_container_add (Gtk_container (button_box), button); //Show window and all its controlsGtk_widget_show_all (Win);}intMainintARGC,Char**argv) {gtkapplication*app; intApp_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); returnApp_status;}

Compile and run the results as follows:

Linux from the beginning again gtk+-3.0 (ii)

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.