PYGTK Simple Tasks

Hi to all,

A long ago Raji akka teached pygtk to us, also i learned pygtk with eager at the time. But after that i didn’t worked it out regularly, fortunately i had to do some simple task in pygtk, I started it from scratch finally i did one Hello World program and Simple currency converter. May be these programs are simple, but it shows i too know pygtk 😉

1. Hello World program

#!/usr/bin/env python
import pygtk
import gtk

class HelloWorld:
    def hello(self, widget, data=None):
        print "Hello World"
    def delete_event(self, widget, event, data=None):
        print "delete event occurred"
        return False
    def destroy(self, widget, data=None):
        print "Completely quit"
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        self.hobox = gtk.HBox(False, 0)
        self.b = gtk.Button("Hello World")
        self.b.connect("clicked", self.hello)
        self.hobox.pack_start(self.b, True, False, 0)
        self.a=gtk.Button("    Exit   ")
        self.a.connect("clicked", self.destroy)
        self.hobox.pack_start(self.a, True, False, 0)
    def main(self):
if __name__ == "__main__":
    hello = HelloWorld()

Here is the screen shot:


To get the output…………?

* Copy and paste the code in text editor.

* save the filename with .py extenstion

* run the file with the following command in terminal python

* You will get a window like above 🙂

2. Simple Currency Converter:

import pygtk
import gtk
class Conversion:
    def convert(self,widget):
    def delete_event(self, widget, event, data=None):
        print "delete event occurred"
        return False
    def destroy(self, widget, data=None):
        print "Completely quit"
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        table=gtk.Table(4, 2, True)
        self.label1=gtk.Label("Enter USD Amount: ")
        table.attach(self.label1, 0, 1, 0, 1)
        table.attach(self.text1, 1,2,0,1)
        self.label2=gtk.Label("Indian Value Is (INR): ")
        table.attach(self.label2, 0,1,1,2)
        table.attach(self.text2, 1,2,1,2)
        self.label3=gtk.Label("Euro Value Is (EUR): ")
        table.attach(self.label3, 0,1,2,3)
        table.attach(self.text3, 1,2,2,3)
    def main(self):
if __name__ == "__main__":
    conversion = Conversion()

Screen shot :

To get the output…………?

As mentioned above do it here also.

* Copy and paste the code in text editor.

* save the filename with .py extenstion

* run the file with the following command in terminal python

* You will get a window like above 🙂

It will help to beginner to learn pygtk.

Thank You

With Regards,
V. Balakrishnan.

Highlighting Code in WordPress

Hi to Everyone,

I am not convenient in posting a blog which contains some commands,languages,source-code etc., For this i have explored some concepts to rectify this problem.

I got <pre> tag to highlight the text which is preformatted tag. So it is very useful to highlight the text We can use <pre > tag in two ways

1st way:

When you writing the post in above to an input window you can see two called “Visual” & “HTML” as shown in the figure you can click in the HTML page. It will takes you to HTML editable page in that you can add the <pre> tag </pre>.


For Ex:

bala@bala-desktop:~$ pwd


bala@bala-desktop:~$ pwd

2nd Way:

Instead of adding <pre> tag in HTML editor you can just select the text what should be highlighted and simply select the preformatted option contains in (Kitchen sink). As default that tool bar is in hide, we can make it visible by using the short cut key Shift + Alt + Z.

Just select the text and click the preformatted option, for this we can do it in Visual tab. Now you can click preview option to see the effect.

I had a problem, now this <pre> tag is not working in my theme as working normally in other themes. Then only i understood that it is the work of theme builder. In my blog if i use the <pre> tag means font will only change the background area remains same. Thats the issue….

I can fix this issue manually by adding the background color to the post (i.e.) Here is the code add this code in your HTML area as shown in the (figure-1). Then type the following <div> tag before your code here pwd command is my content so i have used the div tag at starting and ending. You can change the background color depends upon your theme.


<div style=”color:white; padding:15px; background-color:black;width:600px; font-family:comic sans ms;”>
bala@bala-desktop:~$ pwd

In this <div> tag we change Font colour, Background Colour, Width of the Background, Padding, Font name for your choice.



One more option to paste your code which is useful on posting your blog with some programming and scripting language.


The following languages are supported:

  • actionscript3
  • bash
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • r
  • ruby
  • scala
  • sql
  • vb
  • xml

In this too am having problem, in my theme it has more line spacing between each line So it seems ugly. That image is stated below, I can fix this problem only by changing my theme, Still I am searching to solve this problem without changing the theme.

Hope you can get idea to highlight your code from any of the way which is explained above.

Thank You

With Regards,
V. Balakrishnan

About ChennaiPY meet on 26-02-’11

Hello friends,

Greetings to Everyone.

After long period I had chance to attend the chennaipy monthly meeting. Actually ChennaiPy is a Python group which is conducting in Chennai at every last week of the month. I have decided to attend that meeting so i went to Chennai from Kanchipuram at 1’o clock. I think its too late but i had some works which is very urgent to do. So only i have started on that time. I reached there at 3.45 totally i missed 40 minutes Speech.

When i am entering into the class i saw that Mr. Lakshmi Vyas handling the session with the topic called “Meta Programming”. It is totally new concept for me not only concept that word too. Anyhow i listened it very carefully because it is new concept for me. He explained the class fully in Processional  English, but i cant understand his Hand-writing which was written in that board. After some time he wrote in Capital letters to understand his hand writing.

He explained some programs in live to get clear of that concept. It contains totally 7 programs due to time constraint he can cover upto 5th program. He told that we can cover it on next session but he gave overview of that remaining 2 programs.

From his explanations i got some information
* python Decorators
*Function Returns Function

Also he show a real time project that contains meta programming which was created by himself called “HYDE”.

I Feel that the  Session is very useful and advanced for me…

Thats it.