C Language Learning (2)-GTK layout, C Language Learning-gtk Layout

Source: Internet
Author: User

C Language Learning (2)-GTK layout, C Language Learning-gtk Layout
First, understand the Definition Format of the function in gtk:

Remember the following formats.

Declare variable: GtkAbc * abc = gtk_abc_new () Declare control;

Value assignment: gtk_abc_set_label (controlName, value );

Add to parent container: gtk_container_add (controFather, controlChildl );

Display Control: gtk_widget_show (controlName );

General default value: the last three values of gtk_box_pack_start (), which are generally FALSE, FALSE, and 0.

1. Box layout (vertical and horizontal)

 

# Include <stdio. h> # include <gtk/gtk. h> int main (int argc, char * argv []) {// initialize gtk gtk_init (NULL, NULL ); // define a pointer to the window: GtkWindow * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); // After the form is closed, execute g_signal_connect (window, "destroy", gtk_main_quit, NULL ); // set the title gtk_window_set_title (window, "title"); // each added control must have show gtk_widget_show (window); // Add a box, use vertical layout // GTK_ORIENTATION_HORIZONTAL for horizontal layout GtkBox * box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (window, box); gtk_widget_show (box ); gtkLabel * lb1 = gtk_label_new ("box layout"); gtk_container_add (box, lb1); gtk_box_pack_start (box, lb1, FALSE, FALSE, 0); gtk_widget_show (lb1 ); gtkEntry * entry1 = gtk_entry_new (); gtk_container_add (box, entry1); gtk_box_pack_start (box, entry1, FALSE, FALSE, 0); gtk_widget_show (entry1 ); gtkButton * btn1 = gtk_button_new (); gtk_button_set_label (btn1, ""); gtk_container_add (box, btn1); gtk_box_pack_start (box, btn1, FALSE, FALSE, 0 ); gtk_widget_show (btn1); gtk_main (); return 0 ;}

The running result is as follows:

Gtk_grid_attach (grid1, btn1, 1, 2, 3, 4 ):
Grid1 indicates the parent container;
Btn1 indicates the added control;
1 indicates that the control is a grid on the left;
2 indicates that the control is two grids above it;
3 indicates that the control occupies the width of three grids;
4 indicates that the control occupies the height of four grids;

Remember a few words:

1. the keyword of Grid layout is Grid.
2. gtk_button_set_label () indicates the value assignment, and set_label () is used for the value assignment ()
3. gtk_container_add () should be written after gtk_grid_attach ()
# Include <stdio. h> # include <gtk/gtk. h> int main (int argc, char * argv []) {gtk_init (NULL, NULL); GtkWindow * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (window, "grid layout"); g_signal_connect (window, "destroy", gtk_main_quit, NULL); gtk_widget_show (window); GtkGrid * grid1 = gtk_grid_new (); gtk_container_add (window, grid1 ); gtk_widget_show (grid1); GtkButton * btn1 = gtk_button_new (); break (btn1, "111111"); gtk_grid_attach (grid1, btn1,); gtk_container_add (grid1, btn1 ); gtk_widget_show (btn1); GtkButton * btn2 = gtk_button_new (); Second (btn2, "222222"); gtk_grid_attach (grid1, btn2,); Second (grid1, btn2 ); gtk_widget_show (btn2); gtk_main (); return 0 ;}

The running result is as follows:

Today, I have written so much. I don't have a high goal. I hope to write an article every day. I want to learn more about the details and then I will try to add it.

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.