C Language Learning (2)-GTK layout

Source: Internet
Author: User
Tags gtk

First understand the definition format of functions in GTK:

Keep in mind the following several formats to see the following code

Declaring variables: gtkabc*abc=gtk_abc_new () Declaration control;

Assignment: Gtk_abc_set_label (controlname,value);

Add to Parent container: Gtk_container_add (CONTROFATHER,CONTROLCHILDL);

Display controls: Gtk_widget_show (controlname);

General Default value: Gtk_box_pack_start () after three values, typically false,false,0

1. Box layout (vertical and horizontal)

#include <stdio.h>#include<gtk/gtk.h>intMainintargcChar*argv[]) {    //Initialize GTKGtk_init (null,null); //define a pointer to windowgtkwindow*window=gtk_window_new (Gtk_window_toplevel); //execute after form closesG_signal_connect (window,"Destroy", Gtk_main_quit,null); //Set TitleGtk_window_set_title (window,"title"); //each added control must have a showgtk_widget_show (window); //Add a box to use the vertical layout//gtk_orientation_horizontal for horizontal layoutGtkbox*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,"Button One");    Gtk_container_add (BOX,BTN1); Gtk_box_pack_start (Box,btn1,false,false,0);        Gtk_widget_show (BTN1);        Gtk_main (); return 0;}

The operation results are as follows

2. Grid layout

Principle:

Gtk_grid_attach (grid1,btn1,1,2,3,4):
GRID1 represents the parent container;
BTN1 represents the added control;
1 indicates that the control is a grid from the left;
2 indicates that the control is two meshes from the top;
3 indicates that the control occupies a width of 3 meshes;
4 indicates that the control occupies a height of 4 meshes;

Remember a few words:

1. The key word for grid layout is grid
2.gtk_button_set_label () means assignment, assignment with Set_label ()
3.gtk_container_add () to write after Gtk_grid_attach ()
#include <stdio.h>#include<gtk/gtk.h>intMainintargcChar*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 (); Gtk_button_set_label (BTN1,"111111"); Gtk_grid_attach (GRID1,BTN1,1,1,1,1);    Gtk_container_add (GRID1,BTN1);    Gtk_widget_show (BTN1); Gtkbutton*btn2=gtk_button_new (); Gtk_button_set_label (BTN2,"222222"); Gtk_grid_attach (GRID1,BTN2,0,0,1,1);    Gtk_container_add (GRID1,BTN2);        Gtk_widget_show (BTN2);        Gtk_main (); return 0;}

Running results such as

Today, so much is written, my goal is not high, I hope to write a daily, specific details such as learning in depth, and then slowly Add.

C Language Learning (2)-GTK layout

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.