joi, 28 februarie 2008

A very small but illustrative Python app

I've made another Python application, very small, and am listing the source code here to show how easy it is to write programs in Python. This is a currency converter that converts EUR to USD and vice-versa.

Download it here (remember it's unsigned). Or, better yet, there's no need to download it, just try the code as a script.

Here is the code:

import appuifw, e32, graphics
from graphics import *

def quit():
app_lock.signal()
appuifw.app.set_exit()
def convert():
choice=appuifw.popup_menu([u"EUR to USD", u"USD to EUR"])
if(choice==0):
x=appuifw.query(u"Type the sum", "number")
appuifw.popup_menu([u"%f" % (x*1.473)])
if(choice==1):
x=appuifw.query(u"Type the sum", "number")
appuifw.popup_menu([u"%f" % (x/1.473)])

appuifw.app.exit_key_handler=quit
appuifw.app.title=u"Converter Lite"
appuifw.app.menu=[(u"Convert", convert), (u"Exit", quit)]
appuifw.app.screen='normal'
imgi=Image.new((240,240))
def handle_redraw(rect):canvas.blit(imgi)
canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
appuifw.app.body=canvas

app_lock=e32.Ao_lock()
app_lock.wait()

Niciun comentariu: