Developing desktop apps with Python-Clutter

13 Jul

If you want to develop some practical applications for Linux platforms then you should know at least one gui toolkit for creating user interfaces.So here I’ll show you how to employ one such library which is known as PyClutter(python-clutter).It is used to create windowed applications.Also obviously Python programming language will be used.So let’s dive in.

Installing PyClutter:

If you are using Ubuntu then you can fire up “Ubuntu Software Center” and search for “python-clutter”.Otherwise you can grab the library from here .

Using PyClutter:

First of all we have to set up the base on which our whole interface will be built.For this we will create a basic blank window.Here is the code to do that.

import clutter

def basic():





Save the above code in a file(“…….” are used just to show indentation of code.So delete them,they will result in syntax error if not removed) and run it like any other python script.You’ll see a blank window on executing the script.Breakdown of the above code is as follows

first of all we create an empty stage on which we will draw various elements

next,we call “show_all()” on Stage’s instance which will make every element inside the window visible.Also it’ll make the window visible.

finally we call the “clutter.main()” so that we can see the output.

Now for building real apps we need to know more about this library.

Setting color:

There are two methods to do that



The above code will set the background color of the window to blue.

Method 2:



In the above code we first make the color using rgba technique.If you’ve any idea about html then you might be familiar with this method.Finally we set the color of the window.Any other element’s(like rectangles,texts etc.) color can be set similarly.

Setting size:


The window now will be 500×400.

Setting window title:

stage.set_title(“Basic window”)

Writing Text:


tex.set_text(“Hello There!”)



The above code is self explanatory.Note that the text element should be added to the main window we created.For this,use


When all of the above code will be put together,you’ll get the window like this

Resulting Window


I’ll write more about PyClutter and how to use it for complex apps.Just stay in touch with my site.

The Impatient Developer’s Guide to Python

27 Jun

If you don’t want to go through those 200 pages for just learning the basics of Python but still want to learn Python,you’re at the right place.In this post I’ll be telling you about how to code in Python.I already assume that you at least know the basics of computer programming or have programmed before.So let’s dive in.

First of all,you should understand that Python doesn’t have ‘{‘ and ‘}’ to represent start and end respectively of any structural block so we use indentations to tell the python’s interpreter about start and end of any structural block like functions,if else statements,loops etc.To make things clear i’m gonna show you the example

Example 1: C’s syntax:-  

void sum(){

<programs body>


while in Python the above function will be written as follows

Python’s syntax:-

def sum():

<indentation><program body>

In the above code “<indentation>” denotes that you’ve to indent the program’s body,you don’t have to type the word “<indentation>” though,just press the tab key to indent the code.Now we can proceed further.I’d like to tell you about python’s shell.It’s an interactive place where you can write your commands and have them executed.The symbol “>>>” denotes the Python shell’s prompt.It’s “interactive” because it shows the result immediately after executing the instruction.If you type 2+3 at the “>>>” prompt then you’ll get 5 as output.





Diving In: In order to practice Python,you should start Python’s Interactive Shell.If you’re using Ubuntu or Mac OS X then you must be having Python installed already.If you’re using Windows you can easily get the installer from here.On Ubuntu simply type “python” in the Terminal without quotes.You will get something like this

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Showing output,printing to the console: For this use “print” command.


>>>print(“Hello World”)

Hello World

Defining Variables in Python: For defining simple variables to store integer,float and string like values you can write




There’s no need of doing something like “int var” or “float var” like other programming languages.

Introducing Dictionary,Lists and Tuples: These are unique data types and are very powerful.I’m gonna show you how you can use them,one by one.

Dictionary: You can define a dictionary type variable as follows:


Now you can visualize it as one item list with associated values.In the above case if “name” is an item then “rajat” is it’s value.Now if you want to access value of any item,you can do it as follows



To add new entry,type:


List: You can define a list type variable in the following way:


Now to access the elements from the above list you can do something like this



To add new element to the above list,type


Tuple: You can define a tuple type variable as follows:


Defining Functions: Creating new functions in Python is very easy.Following is the syntax of a function in Python

>>>def <function name>(<arguments list>):

…            <program’s body>

Here is the small example of a function:

>>>def sayhello():

…           print(“Hello”)

Now calling any function is very easy too:



 Defining Class: As Python is an object oriented high level programming language you can obviously create classes in Python.Here’s how you can do this:

>>>class <classname>(<SuperClass,if any>):

…          def  __init__(self):

…                  <init’s body>

…          <rest to the body of this class>

Example of a class:

>>>class myclass:

…              def __init__(self):

…                     print(“Hello”)

Now to make the instance of above class,type:



Looping: Easiest way to doing this is as follows

>>>for i in range(5):

…          print(str(i))






In the above example you must have noticed two new things “str” and “range”,so here’s the explanation.The in built function str() converts integer value to string and the function range() generates a list containing the integer elements from 0 to argument-1 where argument is what we pass to the range() function.Have a look at it



I think if you put the above Python skills under your belt,then you can certainly make simple programs using Python.Under any difficulty feel free to write to me,I’ll try resolve your issue with Python


Which Python book to follow?

11 Jun

If you’ve read my previous post Why learn Python? and you are really impressed to see what python can do for you,you might be wanting to try your hands on python.For this you’ll definitely need a good book of python language which can guide you during the times when you’re stuck somewhere in between.Believe me,a good book can be a great companion and an asset to the programmer.So,I’m gonna review 3 Python books for you to choose from.

Book #1 : Head First Python


Head First Python Cover

If you haven’t programmed before or you don’t want to put too much effort in learning Python,then this book is for you. But it is to be noted that this book is very lengthy and you’ll find many things in the book are redundant.Also,If you are an experienced programmer in Python then this book is not for you.The area where this book scores maximum is that it teaches the user how to build realistic applications using modern technologies rather than explaining Python’s Standard API(Application Programming Interface).

If you use this book,you will be able to:-

  • Write CGI scripts using Python
  • Create apps with Google App Engine which can be used with different social networks
  • Create Android apps
  • Database Management using Python
Book #2 : Programming with Python 3
Programming with Python 3
Huff!Believe me this book is python newbie’s nightmare.If you are a newbie and don’t have any knowledge about python then this book is not for you.On the other hand if you’re an experienced python programmer who wants to increase his/her command over the language,then this book can prove beneficial to you.To tell the truth,I picked up this book in the first place for learning python but the book didn’t really help me.Besides regular stuffs this book will provide you some great topics.
Salient features of this book are as follows:-
  • The chapter on Regular Expressions is really nice
  • The book tells you about Networking using Python
  • The book teaches advance techniques like extracting meta data from files
  • The book teaches about debugging,testing and profiling
Book #3 : Python for Unix and Linux System Administrators
Python for Unix and Linux 
System Administrators Cover
To be frank with you,I’ve not read this book yet but I’ve had a look at it.So I can at least tell you what this book contains.As the name say it all,this book is exclusively for users who use Linux and Unix.
This book has chapters on following topic:-
  • IPython
  • SNMP
  • OS Soup
  • Package Management
  • Using easy_install
  • Processes and Concurrency
Attention : It is to be noted that all of the above books don’t have good chapters on “Building GUIs”.So,if you want to write GUI applications in Python then you have to use other libraries like PyGTK,PyQT etc.Just keep in touch,I’ll be reviewing GUI toolkits for Python soon

What’s Ubuntu?Is there any need to know Ubuntu?

10 Jun

If you have been using Linux for past few days or months,you might have heard the name of Ubuntu.If you come from Windows or Mac background,i’d like to tell you that Ubuntu is the most popular Linux distribution(flavour) on planet Earth.
You should at least give Ubuntu a try in order to know what this OS(Operating System) has to offer.
If you are in love with your Windows or Mac OS X environment,I can still give you enough reasons to try Ubuntu out.

So let me try to convince you to use Ubuntu:)

Reason #1 : You don’t like viruses and malwares,do you?
Solution : Try Ubuntu,it’s virus free

Reason #2 : You don’t like to wait for your OS to start so that you can update your Facebook Status.
Solution : Try Ubuntu,it boots in less than 20 seconds on new systems.
Now,If you argue that your windows system already boots in 15 seconds,I’d say that Ubuntu will boot in 10 seconds only,on your system;)

Reason #3 : You use a lot of pirated softwares and don’t want to pay for softwares in future too.
Solution : Then why not try out the OS which has all the softwares needed for day-to-day computing and all of them are free.
You could ask,”Ok,you say that all of the softwares are free but are they updated too?”.I’d say,”Yes,they are and all of the updates are free too:)”.

Reason #4 : You can still say that your CD/DVD drive is damaged or out of order or may be you own a netbook which doesn’t even has CD/DVD drive,so you are unable to try it out.
Solution : To tell you the truth,Ubuntu can boot from USB drive too.

So,you can try out Ubuntu without any fear.If I was successful in convincing you to use Ubuntu then why not download Ubuntu for your system.Here is the link: Download Ubuntu

In the next post I’ll be telling you about the ways to run Ubuntu on your System.

Why learn Python?

8 Jun

Whether you are a programmer or not,knowing any computer language is not a loss at all.

A good programming should has following qualities:-
-highly reliable
-fast enough
-easy to learn

Python has it all.It is designed to be easy and fast.Also the programs written in Python can be easily understood by human beings.

If you learn this language,you’d be able to:-
-write programs which can control your operating systems,it is the core programming language on Ubuntu.
-write applications for Android platform.
-write CGI scripts.
-write utility programs like Image Viewer.
-develop applications for social platforms like Facebook.
-create database applications without even installing any dbms as Python has in-built SQLite database system.
-run your own webserver and show off your contents to the world

Also there is nothing which will stop you from using Python.There are python-bindings(libraries) for everything.For example:-
-want to develop high quality GUIs?Use Pyclutter
-want to embed a web browser into your app?Use gtkmozembed
-want to process XML?Use lxml

I think all of the above would be enough to convince you to use Python for your programming purposes.

Facebook Indicator

7 Jun

I’ve developed a simple python script which can show your fb notifications using Ubuntu’s in-built OSD system.

You can check it out at:

I’ve joined WordPress

6 Jun

They say WordPress is best.Now let me see that how efficiently this site can serve my blogging needs.