pyFltk2 - Python module for the FLTK2 GUI toolkit.
FLTK2 is a new generation toolkit for creating GUI applications for UNIX/X11, MS
Windows and Mac. It is a further development of the well known FLTK toolkit by the same authors. This module allows you to write programs with this
toolkit in Python without the fuss of C++. FLTK2 was created by Bill Spitzak and others and can be found
on the web at http://www.fltk.org.
FLTK2 is still not stable, there have not been any official releasese yet and to wrap it is a moving target.
This document will not cover all the details on using the FLTK2 toolkit. For complete instructions on the FLTK2 API consult the manual that comes with the source code or see the latest manual on the FLTK2 website. This document will cover the differences in using pyFLTK2 and provide some examples.
The Python syntax for FLTK2 is very similar to using it in C++. To declare a new window, simply use:
window = Window( width, height, label)
As FLTK2 takes posession of all the widgets that are created, the
Python garbage collector will attempt to delete widgets that have
already been deleted by FLTK2, or vice-a-versa. To avoid this,
thisown
is internally set to 0 for every created widget.
If it is necessary to explicitly delete a window, then thisown
has to be set to 1, prior to deleting.
All widgets are declared in a similar manner. After a new window or group
is declared all widgets declared after it will be inserted into it until
the end()
member function is called. This is the same as using the C++ API, so
consult the FLTK2 documentation for further info.
Callbacks do the work of your program. To get a widget to respond to events
sent to it you must assign a callback function to it. This is done using
the
callback(sub-name, data)
function:
def button_cb(ptr, data): # do something . . . button = Button(10, 10, 40, 20, "Button") button.callback(button_cb, "I am a button") . . .
Here's some quick example scripts to get you going, starting with the ubiquitous Hello World:
from fltk2 import * import sys
def btn_cb(ptr): sys.exit(0) window = Window(200, 90, "hello.py") button = Button(9, 20, 180, 50, "Hello World") button.callback("btn_cb") window.end()
run() #starts the event loop
Bill Spitzak <spitzak@cinenet.net> FLTK Author Micheal Sweet <mike@easysw.com> FLTK Maintainer Kevin Dahlhausen <morse@harborcom.net> Originator of pyFltk Matt Kennedy <mkennedy@odysseys.net> Originator of Perl FLTK module
Andreas Held <a.held@computer.org> Python FLTK module
The FLTK2 Manual. Available at http://www.fltk.org pyFltk homepage at http://pyfltk.sourceforge.com