[Tutoriel] Glade3 and PyGi



In this article you will understand the basics of creating a user interface using Glade3 (User Interface Designer) and PyGi (PyGObject).
This tutorial will discuss a simple and basic example and will focus on the call PyGi methods and how to bind an XML file generated by Glade3 and our code PyGi.
Enough talk! ! Let’s begin …

Creating a window type Top Level named (the id) Window1



Change the view of the window and force her to appear at the screen center:


Change the title of the window:


Edit the dimensions of the default window:


Use Grid as Container (The list of container is grouped on Glade , but in this example we will use only Grid with a 3×3 dimension named Grid1):


La window will be divided as follows:



Our Grid will automatically be added to the hierarchy of Window1


In Grid1 Adding these Widgets listed in the fields Control and display of Glade3 . We will have an interface similar to cella:



The list of items and their type added to Window1 appear as follows:


We modify the properties of button1 (button added to Windows1 ). It changes the name that appears on the button and renames out


a signal is added (event) to button1 type clicked and it is related to the signal method on_button


a signal is added (event) to comboboxtext1 type changed and it is related to the signal method on_comboboxtext


added the signal (event) to checkbutton1 type toggled and it is related to the signal method on_toggle



the signal is added (event) to entry1 type activate and it is related to the signal method on_entry_activate


the signal is added (event) to searchentry1 and type activate and it is related to the signal method on_entry_activate


The software will appear as follows:


For the widget checkbutton1 we’ll do it manually by editing the XML file generated by Glade . We will add the signal to child switch1 (which means switch1 is the child of Window1 ) like this:


  

This line results with PyGi in:

 switch1.connect ( "notify :: active" on_switch_activate) 

That said link switch1 a signal type :: notify active (active notification)

Without much spread the tutorial, here is the XML file generated by Glade3 and source code PyGi with comments to understand the use and operation of each line


source Code XML file Glade3.


  False  Glade3 Test & amp; PyGi (python3)  center-always  500  250  True  False  out  True  True  True  top  0  0  1  1  True  True  1  0  1  1  True  False  on  NeXus  Nymph  Tristiana  Auroroe  Liturgy  2  0  1  1  checkbutton  True  True  False  0  True  0  1  1  1  radiobutton  True  True  False  0  True  True  1  1  1  1  True  True  Put your text and press Enter  1  2  2  1  True  True  edit-find-symbolic  False  False  2  1  1  1 




 #! / User / bin / python# - * - Coding: utf-8 - * -

No comments:

Powered by Blogger.