Showing posts with label learn python. Show all posts
Showing posts with label learn python. Show all posts

Wednesday, August 03, 2011

A Usefull PyGTK Example

I have been looking for a good pygtk tutorial for a very long time. I have found a few tutorials which where an overkill, so I don't link to them. By over kill I mean that they where full with details which prevented me from actually having an application working.
I found this nice pygtk tutorial, which is actually more a capabilities demonstration. After reading for a few hours, I got intrigued. But I was very frustrated since the tutorial does not produce any real life example. For example, I would have expand the calculator example to working one. I did a Google search and bumped into this pygtk calculator working example. After a couple of more hours, I have managed to produce the following "Hello World!" pygtk application which demonstrates some basic pygtk principles:

#!/usr/bin/python

# A Usefull and Active PyGTK Example
#
# This example demonstrates a few Widgets which actually do 
# some stuff, and interact with each other.
#
# oz nahum
# linuxpixies.blogspot.com 
# August 2011

import gtk

class PyApp(gtk.Window):

    def __init__(self):
        super(PyApp, self).__init__()
        
        self.set_title("Entry")
        self.set_size_request(250, 200)
        self.set_position(gtk.WIN_POS_CENTER)

        self.fixed = gtk.Fixed()

        self.label = gtk.Label("Please Enter Your Name below")
        self.fixed.put(self.label, 60, 40)
        
        self.entry = gtk.Entry()
        self.entry.add_events(gtk.gdk.KEY_RELEASE_MASK)
        self.fixed.put(self.entry, 60, 100)
        
        self.entry.set_text("bla")
        self.UserName=self.entry.get_text()  

        self.outlabel=gtk.Label('name')
        self.fixed.put(self.outlabel, 60,180)
        
        self.button = gtk.Button("Greeting:")
        self.fixed.put(self.button, 60,140)
        self.button.connect("clicked",self.greeting)
        
        self.clearbutton = gtk.Button("Clear")
        self.fixed.put(self.clearbutton, 140,140)
        self.clearbutton.connect("clicked",self.cleartxt)
       
        self.button = gtk.Button("Close")
        self.button.connect("clicked",gtk.main_quit)
        self.fixed.put(self.button, 200,140)

        self.connect("destroy", gtk.main_quit)
        self.add(self.fixed)
        self.show_all()
        
    def greeting(self, event):
        self.outlabel.set_text("Hello "+self.UserName)
        self.entry.set_text('Hello '+self.UserName)
        
    def cleartxt(self, event):
        self.entry.set_text("")

PyApp()
gtk.main()

Sunday, June 19, 2011

One more python learning resource

This one is pretty cool. It is a learning environment, which allows you also to create more learning environment. I wish I had more time to play with it!
Python Crucny: http://code.google.com/p/crunchy/

Have fun!


Thursday, May 26, 2011

2 Cool Python Learning resources

A couple of nights ago I was browsing code.google.com in random search for interesting Python projects.
Here are two nice catches from my random fishing, which are worth mentioning. The first one is a Free python book, which attempts to bring Python and the joy of creating software for kiddies, here is what they write as an intro:

"Snake Wrangling for Kids" is a printable electronic book, for children 8 years and older, who would like to learn computer programming. It covers the very basics of programming, and uses the Python 3 programming language to teach the concepts.

The second one, is a Python interactive learning program. Although I have not played a lot with it, it seems fun. However, the project seems a little bit sleepy (no updates for almost a year):

RUR-PLE is an environment designed to help you learn computer programming using the language Python. Within an artificial world in which a robot can be programmed to perform various tasks, you will learn what it means to write a computer program, using Python's syntax

If you are a self learner type like me, you would appreciate these resources.