Hello World¶
To continue long-standing programming traditions, we'll start with a simple program that outputs 'Hello World' on the screen:
minimal.py:
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4from libavg import avg
5
6player = avg.Player.get()
7canvas = player.createMainCanvas(size=(640,480))
8rootNode = canvas.getRootNode()
9avg.WordsNode(pos=(10,10), font="arial",
10 text="Hello World", parent=rootNode)
11player.play()
You can start the program by opening a console, changing into the sample directory and typing
1./minimal.py
You can stop the program by pressing the Esc key.
The first two lines of code tell the system that this is a python file and that it's encoded in utf-8. This encoding is standard for all libavg programs. The following lines create a window to draw in (createMainCanvas()
) and put some text in that window (the WordsNode line). After this scene is initialized, it is shown (player.play()
).
Development Environment¶
This tutorial assumes you'll be working with a text editor and the command line. That doesn't mean that's the only way to work with libavg. For instance, Eclipse together with the PyDev Plugin works very well as an IDE for libavg.
'No module named avg' error¶
If you get an 'ImportError: No module named avg
', Make sure Python can find libavg. You can change the environment variable PYTHONPATH to point to the directory the library is in. On Mac and Windows, the standard installer should have taken care of setting this up correctly. Under Linux, the place where libavg was installed isn't completely standardized. Possible places are:
libavg install paths
/usr/local/lib/pythonX.Y/site-packages/libavg /usr/lib/pythonX.Y/site-packages/libavg /usr/local/lib/pythonX.Y/dist-packages/libavg /usr/lib/pythonX.Y/dist-packages/libavg
If some other error appears, feel free to ask on the libavg-user mailing list, preferrably with a concise description of what went wrong.