GTK Basic Learning Summary (i)

Source: Internet
Author: User
Tags gtk

Example of the first GTK program:

#include <stdio.h>

#include <gtk/gtk.h>

int main (int argc, char *argv[])

{

Gtk_init (Null,null); Initialize GTK

Gtkwindow *window =gtk_window_new (gtk_window_toplevel); Create a new Windows window

Gtk_window_set_title (window, "Windows title"); Set Window Caption

G_signal_connect (window, "destroy", gtk_main_quit,0); Set the "Destroy" signal (event) handler function for the window "Gtk_main_quit ()"

Gtk_widget_show (window); Display window

Gtk_main (); Program blocking

return 0;

}

First, the common method

Widget manipulation functions

void Gtk_widget_show (widget);

void Gtk_widget_hide (widget);

void Gtk_widget_set_sensitive (widget,sensitive);

void Gtk_widget_set_size_request (Widget,width,height);

Window action function

Gtk_window_set_resizable (window,resizable);

Gtk_window_set_position (window,gtk_win_pos_center_always);

Gtk_window_maximize (window);

Gtk_container_add (Container,widget); Install widgets into container

GTK_AAA_GET_BBB ();

GTK_AAA_SET_BBB ();

Gtk_widget_set_title (widget, "title");

Second, gtkbox (box) layout

Create a Box

Gtkbox *box1=gtk_box_new (gtk_orientation_horizontal,0);

Gtkbox *box1=gtk_box_new (gtk_orientation_vertical,0);

Gtk_container_add (Window,box1);

Gtk_widget_show (Box1);

Add button 1

Gtkbutton *btn1=gtk_button_new ();

Gtk_button_set_label (BTN1, "button 1");

Gtk_box_pack_start (box1,btn1,false,false,0);

Gtk_widget_show (BTN1);

Add button 2

Gtkbutton *btn2=gtk_button_new ();

Gtk_button_set_label (BTN2, "button 2");

Gtk_box_pack_start (box1,btn2,false,false,0);

Gtk_widget_show (BTN2);

Add a text box 1

Gtkentry *entry1=gtk_entry_new ();

Gtk_box_pack_start (box1,entry1,false,false,0);

Gtk_widget_show (Entry1);

Three, Grid layout

/*

Gtkgrid *grid1=gtk_grid_new ();

Gtk_container_add (WINDOW,GRID1);

Gtk_widget_show (GRID1);

Gtk_grid_attack (gtkgrid,widget,int left,int top,int width,int height);

Add button 1

Gtkbutton *btn1=gtk_button_new ();

Gtk_button_set_label (BTN1, "button 1");

Gtk_grid_attach (grid1,btn1,0,0,1,1);

Gtk_widget_show (BTN1);

Add button 2

Gtkbutton *btn2=gtk_button_new ();

Gtk_button_set_label (BTN2, "button 2");

Gtk_grid_attach (grid1,btn2,1,0,1,1);

Gtk_widget_show (BTN2);

Add button 3

Gtkbutton *btn3=gtk_button_new ();

Gtk_button_set_label (Btn3, "button 3");

Gtk_grid_attach (grid1,btn3,0,1,2,2);

Gtk_widget_show (BTN3);

*/

Attached: The above content for I learned Yang Zhengko teacher's "C language also can do big Things (third edition)" Teaching video, the content of the study of the summary.

GTK Basic Learning Summary (i)

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.