Glade and GTK

Source: Internet
Author: User

 

Glade2 and glade 3

Libglade

GTK + and glade3 GUI Programming Tutorial

GTK interface development toolsGtkbuilder

Getting started with Glade 3 and GTK +-2

 

Knowledge Point

glade3 and glade2 difference
glade2 Generate Code , glade3 only Generate XML file (separated from the code and called in other languages, such as Python)

How to runGlade3GeneratedXMLInterface
WithLibgladeLibrary readXMLFile and generate controls

 

Example

Test. glade

 

 <?  XML version = "1.0" encoding = "UTF-8" standalone = "no"  ?>  <!  Doctype Glade-Interface System "glade-2.0.dtd"  >  <! --  Generated with glade3 3.4.0 on TUE Nov 20 14:05:37 2007  -->  <  Glade-Interface  >   <  Widget  Class  = "Gtkwindow"  ID  = "Window1"  >      <  Property  Name  = "Events"  > Gdk_pointer_motion_mask | gdk_pointer_motion_hint_mask | gdk_button_press_mask | gdk_button_release_mask </  Property  >     <  Child  >        <  Placeholder  />      </  Child  >    </  Widget  >  </  Glade-Interface  > 

 

 

InTest. gladeUnder the same level directory, write the source codeMain. c

 

# Include <GTK/GTK. h> # Include <Glade/glade. h> Int Main ( Int Argc, Char ** Argv) {gladexml * Gxml; gtkwidget * Window; gtk_init ( & Argc ,&Argv); gxml = Glade_xml_new ( "  Test. glade  " , Null, null ); //  Read XML files  Window = Glade_xml_get_widget (gxml, "  Window1  " ); //  Get the pointer named window1 Control G_object_unref (g_object (gxml); gtk_widget_realize (window); gtk_widget_show (window); gtk_main ();  Return   0  ;} 

 Compile

GCC main. C-o main 'pkg-config -- Libs -- cflags GTK +-2.0 libglade-2.0'

Execution result
./Main
DisplayGTKCreated window

 

Since the version of GTK is upgraded to 2.12, it contains gtkbuilder .(PKG-config -- modversion GTK +-2.0 view version)
The function of gtkbuilder is the same as that of libglade. It is used to loadGladeFile,
Therefore, if you use gtkbuilder to replace libglade, you can reduce a dependency during use.

Main. c

 /*  First Run tutorial. glade through GTK-builder-convert with this command: GTK-builder-convert tutorial. glade tutorial. XML then save this file as main. C and compile it using this command (those are backticks, not single quotes): gcc-wall-g-o main. c 'pkg-config -- cflags -- libs GTK +-2.0 '-export-dynamic then execute it using :. /tutorial  */  # Include <GTK/GTK. h> Void  On_window_destroy (gtkobject * Object  , Gpointer user_data) {gtk_main_quit ();}  Int  Main (  Int Argc, Char * Argv []) {Gtkbuilder * Builder; gtkwidget * Window; gtk_init ( & Argc ,& Argv); Builder = Gtk_builder_new (); gtk_builder_add_from_file (builder,  "  Test. glade  "  , Null); window = Gtk_widget (gtk_builder_get_object (builder, "  Window1  "  ); Gtk_builder_connect_signals (builder, null); g_object_unref (g_object (builder); gtk_widget_show (window); gtk_main ();  Return   0  ;} 

 

Use python to call XML

Test. py

 

ImportGTKImportGTK. gladeDefSome_handler (widget ):PassXML= GTK. glade. XML ('Test. glade') Widget= Xml. get_widget ('Window1') XML. autoconnect ({'Some_handler': Some_handler}) GTK. Main ()

 

 

End

 

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.