Linux from the beginning to go GTK +-3.0 (4), gtk-3.0

Source: Internet
Author: User

Linux from the beginning to go GTK +-3.0 (4), gtk-3.0

In practical applications, there are often many controls. Similarly, GTK provides many layout schemes, such as Box, Fixed, Table, and Grid.

Next, try Grid layout.

We create example4.c with the following content:

# Include <gtk/gtk. h> static void print_hello (GtkWidget * button, gpointer data); static void activate (GtkApplication * app, gpointer data); int main (int argc, char ** argv) {GtkApplication * app; int app_status; app = gtk_application_new ("org. rain. gtk ", 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;} static void print_hello (GtkWidget * button, gpointer data) {printf ("Hello, World! \ N ");} static void activate (GtkApplication * app, gpointer data) {GtkWidget * window; GtkWidget * grid; GtkWidget * button; // create a window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "grid test"); // gtk_window_set_default_size (GTK_WINDOW (window), 200,200 ); // create grid = gtk_grid_new (); // Add the grid layout to the window. gtk_container_set_border_width (GTK_CONTAINER (window), 20); gtk_container_add (GTK_CONTAINER (window), grid ); // Add the button to the position (0, 0), and set the height. The width is the unit of button = gtk_button_new_with_label ("Button1"); g_signal_connect (button, "clicked ", g_CALLBACK (print_hello), NULL); gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1); // Add a button to the position (1, 0, and set the height. The width is the unit of button = gtk_button_new_with_label ("Button2"); g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL); gtk_grid_attach (GTK_GRID ), button, 1, 0, 1, 1); // Add a button to the position (0, 1), and set the height to a unit, the width is two units: button = Response ("Exit"); g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_grid_attach (GTK_GRID), button, 2, 0, 1, 1); // Add a button to the position (), and set the height to one unit. The width is two units. The button = gtk_button_new_with_label ("Exit "); trim (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_grid_attach (GTK_GRID (grid), button, 1, 1, 2, 1); gtk_widget_show_all (window );}

Compile and run:

gcc exampe.c `pkg-config --cflags --libs gtk+-3.0`./a.out

Running result:

 

Gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1 );
The following four parameters of the function are represented in sequence: row number, column number, horizontal span, and vertical span.

Related Article

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.