How to create a GUI(Graphical User Interface) using C programming Language.. (part 2)

13 08 2011

Hi, this is the second part of the How to create a GUI(Graphical User Interface) using C programming Language..   post. In today’s post I’m going to tell you how to use Glade software to design a GUI for a C program. Now I think you have prepared your development environment😀.First we need to recognise the Glade environment..

  • Open glade, then you will a window like this. In the Top Levels tab of Palette select window and click on Editor.Then you will a Gray colour window on it. In the inspector view you can change the name of the window. To change the size and other properties go to properties.  This is not much smiler to Net-beans IDE, aligning component is much difficult. But this is much easier than hard coding🙂.
  • Now we should add a container for the window to keep the other component on it. In the Containers tab of Palette select one of containers like Vertical Box then click on the Editor’s window.
  • Then It will look like this. But for example if you add a button component to one of this cell, it fills all overt the cell. But if you need you can further divide into more cells adding one or more containers. For example here I will add another table container into middle cell. Then it will look like this.
  • Ok now I’m going to add some component to it. Under Control and Display tab of the palette, find Button and Text Entry widgets(components), so add it the container.

Ok now Save the GUI you designed. In the Save or Save As menu, there are two options to save.

  1. GtkBuilder
  2. Libglade

Choose the File Format Libglade, and save it as hello_world.glade, because in this tutorial I work with libglade. If you just look at your .glade file by opening with Texteditor. You will see XML coding there.. Yes! of course .glade is XML file format. GtkBuilder file type also generates the same .glade file. But when taken in the file structure GtkBuilder and Libglage are different from each other.

Now I think you may wondering how to connect this Button signals(Actions) to a C program ??

Now click on the Button of your GUI, then click Signals tab under the Properties. Then find Clicked and select on_button1_clicked (Button’s name property is ‘button1’ , so the signal name become on_button1_clicked). Now Save changes.

After we set the signals in our GUI in the glade, we can simply call them (as example) like this.

void on_button1_clicked(GtkWidget *widget,gpointer *data){

// your custom code here!

}// end method

Ok in next post we will discuss how run a hello_world GUI program using C😀.

 

Thank you

Gihan De Silva


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: